diff options
author | Stephan Herrmann | 2010-04-02 03:54:26 +0000 |
---|---|---|
committer | Stephan Herrmann | 2010-04-02 03:54:26 +0000 |
commit | 13a070b9f9759d52b4fc3ee1d3aa35b29c2867d7 (patch) | |
tree | cb64ab5b79e392b5ded169e2c43d043b3d13ae8a /org.eclipse.jdt.core.tests.compiler | |
parent | e5d6be89e15a96492d4f4e9c63a2d2aa53f53492 (diff) | |
download | org.eclipse.objectteams-13a070b9f9759d52b4fc3ee1d3aa35b29c2867d7.tar.gz org.eclipse.objectteams-13a070b9f9759d52b4fc3ee1d3aa35b29c2867d7.tar.xz org.eclipse.objectteams-13a070b9f9759d52b4fc3ee1d3aa35b29c2867d7.zip |
update jdt.core tests to v_A39 using patch from the corresponding update in old svn (for 1.4.0)
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler')
28 files changed, 2487 insertions, 275 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java index 25d7a6d7d..33d948a31 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java @@ -12,9 +12,11 @@ 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; @@ -45,7 +47,7 @@ public SourceElementParserTest(String testName, char[] source) { this.source = source; } static { -// TESTS_NUMBERS = new int[] { 99662 }; +// TESTS_NUMBERS = new int[] { 81 }; } public static Test suite() { return buildAllCompliancesTestSuite(SourceElementParserTest.class); @@ -228,7 +230,7 @@ public void enterType(TypeInfo typeInfo) { if (typeInfo.typeParameters != null) { for (int i = 0, length = typeInfo.typeParameters.length; i < length; i++) { TypeParameterInfo typeParameterInfo = typeInfo.typeParameters[i]; - addTypeParameter(typeParameterInfo); + addTypeParameterToType(typeParameterInfo); } } } @@ -280,11 +282,11 @@ protected void enterAbtractMethod(MethodInfo methodInfo) { if (methodInfo.typeParameters != null) { for (int i = 0, length = methodInfo.typeParameters.length; i < length; i++) { TypeParameterInfo typeParameterInfo = methodInfo.typeParameters[i]; - addTypeParameter(typeParameterInfo); + addTypeParameterToMethod(typeParameterInfo); } } } -public void addTypeParameter(TypeParameterInfo 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}; @@ -296,6 +298,18 @@ public void addTypeParameter(TypeParameterInfo typeParameterInfo) { 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) { @@ -318,13 +332,16 @@ protected void exitAbstractMethod(int declarationEnd) { public void fullParse(String s, String testName) { this.fullParse(s, testName, false); } -public void fullParse(String s, String testName, boolean recordLocalDeclaration) { +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(getCompilerOptions()), + new CompilerOptions(options), recordLocalDeclaration/*don't record local declarations*/, true/*optimize string literals*/); @@ -332,6 +349,9 @@ public void fullParse(String s, String testName, boolean recordLocalDeclaration) 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; @@ -5277,6 +5297,83 @@ public void _test80() { 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<T extends AbstractData> {}\n" + + "\n" + + " private static interface ValueObjectPropertyIterator {\n" + + " public <T extends AbstractData> void iterateOnValueObjectProperty(IScalarData<T> scalarObject, T valueObject, Class<?> valueObjectType, final String name, final Class<?> scalarType) throws Exception;\n" + + " }\n" + + "\n" + + " private static <T extends AbstractData> void iterateOnValueObjectProperties(IScalarData<T> scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator) {}\n" + + " \n" + + " public static <T extends AbstractData> void loadScalarFromValueObject(IScalarData<T> scalarObject, T valueObject) {\n" + + " iterateOnValueObjectProperties(scalarObject, valueObject, new ValueObjectPropertyIterator() {\n" + + " public <T extends AbstractData> void iterateOnValueObjectProperty(IScalarData<T> scalarObject, T valueObject, Class<?> valueObjectType, String name, Class<?> scalarType) throws Exception {\n" + + " if (true) {\n" + + " if (true) {\n" + + " if (true) {\n" + + " final Collection<IScalarData<AbstractData>> lazyCollection = createLazyCollection(\n" + + " name, scalarType, null, null,\n" + + " new CollectionProviderForTargetCollection<IScalarData<AbstractData>>() {\n" + + " @Override\n" + + " public Collection<IScalarData<AbstractData>> provideCollection(\n" + + " final Collection<IScalarData<AbstractData> targetCollection, final Class<IScalarData<AbstractData>> scalarCollectionType) {\n" + + " return null;\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " abstract class CollectionProviderForTargetCollection<S> {\n" + + " abstract public Collection<S> provideCollection(Collection<S> targetCollection, Class<S> scalarCollectionType);\n" + + " }\n" + + "\n" + + " private <S> Collection<S> createLazyCollection(String name,\n" + + " Class<?> scalarType, final Collection<AbstractData> valueObjectCollection,\n" + + " final Class<S> scalarCollectionType, CollectionProviderForTargetCollection<S> 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<T> scalarObject, T valueObject, Class<?> valueObjectType, String name, Class<?> scalarType, ) throws Exception, {}\n" + + " }\n" + + " java.lang.Object(0)\n" + + " private static void iterateOnValueObjectProperties(IScalarData<T> scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator, ) {}\n" + + " public static void loadScalarFromValueObject(IScalarData<T> scalarObject, T valueObject, ) {}\n" + + "}"; + + String testName = "test81: full parse"; + fullParse(s,testName, options); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} //{ObjectTeams: add OT-specific methods (should these be implemented??): public void acceptBaseReference(char[][] typeName, int sourceStart, int sourceEnd) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java index c549bced7..2ee2409e9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java @@ -33,6 +33,8 @@ public final class SourceType { private int numberOfFields; private char[] source; SourceType parent; + char[][] typeParameterNames; + char[][][] typeParameterBounds; // Buffering. private char[] qualifiedName; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 0da80b232..90e19f53f 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1170,7 +1170,7 @@ protected static class JavacTestOptions { protected void runConformTest(String[] testFiles, String expectedOutputString) { runTest( - // test directory preparation + // test directory preparation true /* flush output directory */, testFiles /* test files */, // compiler options @@ -1871,6 +1871,39 @@ protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { JavacTestOptions.DEFAULT /* default javac test options */); } protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + String expectedErrorString) { + 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 /* default javac test options */); + } + protected void runNegativeTest( String[] testFiles, String expectedProblemLog, String[] classLibraries, diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java index a83206608..9fc65eaeb 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -2913,7 +2913,7 @@ public void test068() { "interface C extends B, A {}\n" + "interface D extends A, B {}\n" + "public class X<T> {\n" + - " public static void main(String[] args) {\n" + + " public void bar() {\n" + " C c = null;\n" + " X<? extends B> c_b = c.foo();\n" + " D d = null;\n" + @@ -3528,4 +3528,322 @@ public void test080() { }, "SUCCESS"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test081() { + this.runConformTest( + new String[] { + "C.java", + "class A<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\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<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\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<ModelType extends D, ValueType> extends I<ModelType, ValueType> {\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<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\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<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\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<E, CharSequence> implements I<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\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<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\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<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\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<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\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<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\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<ModelType extends D, ValueType> {\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<E, CharSequence> {\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>(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E<Type extends CharSequence> extends D {\n" + + " private Class<Type> typeClass;\n" + + " public E(Class<Type> 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<ModelType, ValueType> {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In A.set(Object)"); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java index 14f2036db..3d98bcf72 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 295551 *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -44,7 +45,7 @@ public class AnnotationTest extends AbstractComparableTest { // All specified tests which do not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test127" }; -// TESTS_NUMBERS = new int[] { 278 }; +// TESTS_NUMBERS = new int[] { 286 }; // TESTS_RANGE = new int[] { 249, -1 }; } @@ -997,7 +998,7 @@ public class AnnotationTest extends AbstractComparableTest { this.runConformTest( new String[] { "X.java", - "@Foo(type=String.class) public class X {\r\n" + + "@Foo(type=String.class) public class X {\n" + "}" }, "", @@ -1246,8 +1247,8 @@ public class AnnotationTest extends AbstractComparableTest { "}\n" }, "----------\n" + - "1. ERROR in X.java (at line 12)\r\n" + - " public @MyAnn void something() { } \r\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"); @@ -2723,8 +2724,8 @@ public class AnnotationTest extends AbstractComparableTest { "}\n" }, "----------\n" + - "1. ERROR in X.java (at line 4)\r\n" + - " @Inherited\r\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Inherited\n" + " ^^^^^^^^^^\n" + "The annotation @Inherited is disallowed for this location\n" + "----------\n"); @@ -2958,8 +2959,8 @@ public class AnnotationTest extends AbstractComparableTest { "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 3)\r\n" + - " @Target(Element)\r\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Target(Element)\n" + " ^^^^^^^\n" + "Element cannot be resolved to a variable\n" + "----------\n"); @@ -4064,7 +4065,11 @@ public class AnnotationTest extends AbstractComparableTest { " class S implements Serializable {\n" + " ^\n" + "The serializable class S does not declare a static final serialVersionUID field of type long\n" + - "----------\n"); + "----------\n", + null, + true, + null, + "java.lang.Error"); } // check @SuppressWarning support //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89436 @@ -4368,8 +4373,8 @@ public class AnnotationTest extends AbstractComparableTest { public void test140() { String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 ? "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " static void foo(){} \r\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" @@ -4503,6 +4508,8 @@ public class AnnotationTest extends AbstractComparableTest { 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); @@ -4534,16 +4541,21 @@ public void test142c() { }, null, raiseDeprecationReduceInvalidJavadocSeverity, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X extends p.OldStuff {\n" + - " ^^^^^^^^^^\n" + - "The type OldStuff is deprecated\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " super.foo();\n" + - " ^^^^^^^^^^^\n" + - "The method foo() from the type OldStuff is deprecated\n" + + "----------\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); } @@ -5831,10 +5843,10 @@ public void test143() { "import static java.lang.annotation.RetentionPolicy.*;\n" + "import java.lang.annotation.Retention;\n" + "import java.lang.annotation.Target;\n" + - "@Target({TYPE, FIELD, METHOD,\r\n" + - " PARAMETER, CONSTRUCTOR,\r\n" + - " LOCAL_VARIABLE, PACKAGE,})\r\n" + - "@Retention(CLASS)\r\n" + + "@Target({TYPE, FIELD, METHOD,\n" + + " PARAMETER, CONSTRUCTOR,\n" + + " LOCAL_VARIABLE, PACKAGE,})\n" + + "@Retention(CLASS)\n" + "public @interface X {}" }, "", @@ -6327,8 +6339,8 @@ public void test193() { "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " A circular1();\r\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" @@ -6345,18 +6357,18 @@ public void test193() { "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " B circular2();\r\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)\r\n" + - " A circular1();\r\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)\r\n" + - " A circular();\r\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" @@ -6373,18 +6385,18 @@ public void test193() { "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " A circular1();\r\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)\r\n" + - " B circular2();\r\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)\r\n" + - " A circular();\r\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" @@ -7091,8 +7103,8 @@ public void test215() { if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) { this.runNegativeTest(sources, "----------\n" + - "1. ERROR in Y.java (at line 3)\r\n" + - " public void foo() {}\r\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"); @@ -8147,8 +8159,8 @@ public void test248() { "}" }, "----------\n" + - "1. ERROR in TestAnnotation.java (at line 2)\r\n" + - " String targetItem() default void.class;\r\n" + + "1. ERROR in TestAnnotation.java (at line 2)\n" + + " String targetItem() default void.class;\n" + " ^^^^^^^^^^\n" + "Type mismatch: cannot convert from Class<Void> to String\n" + "----------\n"); @@ -9279,4 +9291,231 @@ public void test278() { expectedOutput, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } +// 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, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//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 field A.i is never read locally\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); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index 43bcf84c2..a1a34b54e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Benjamin Muskalla - Contribution for bug 239066 * Stephan Herrmann - Contribution for bug 236385 + * Stephan Herrmann - Contribution for bug 295551 * Technical University Berlin - adapted for Object Teams *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -48,8 +49,8 @@ public class BatchCompilerTest extends AbstractRegressionTest { static { // TESTS_NAMES = new String[] { "test292_warn_options" }; -// TESTS_NUMBERS = new int[] { 295 }; -// TESTS_RANGE = new int[] { 107, -1 }; +// TESTS_NUMBERS = new int[] { 298 }; +// TESTS_RANGE = new int[] { 298, -1 }; } public BatchCompilerTest(String name) { super(name); @@ -1735,7 +1736,9 @@ public void test012b(){ " static-access macro for indirectStatic and staticReceiver\n" + " staticReceiver + non-static reference to static member\n" + " super overriding a method without making a super invocation\n" + - " suppress + enable @SuppressWarnings\n" + + " suppress + enable @SuppressWarnings\n" + + " When used with -err:, it can also silent optional\n" + + " errors and warnings\n" + " syncOverride missing synchronized in synchr. method override\n" + " syntheticAccess synthetic access for innerclass\n" + " tasks(<tags separated by |>) tasks identified by tags inside comments\n" + @@ -1883,6 +1886,7 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" value=\"warning\"/>\n" + @@ -11269,4 +11273,163 @@ public void test297(){ "invalid error configuration: \'-err\'\n", true); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test298(){ + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -err:+unused,suppress -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test299(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -err:+unused -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " @SuppressWarnings(\"unused\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The field X.i is never read locally\n" + + "----------\n" + + "2 problems (1 error, 1 warning)", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test300(){ + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -warn:-suppress -err:+suppress,unused -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test301(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -warn:-suppress -err:+unused -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The field X.i is never read locally\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test302(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -warn:-suppress -err:+suppress,unused -warn:-suppress -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The field X.i is never read locally\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test303(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -warn:-suppress -err:+suppress,unused -warn:+suppress -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " @SuppressWarnings(\"unused\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The field X.i is never read locally\n" + + "----------\n" + + "2 problems (1 error, 1 warning)", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test304(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -err:+suppress,unused -warn:-suppress -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The field X.i is never read locally\n" + + "----------\n" + + "1 problem (1 error)", + true); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java index 6e9c60a56..fb65fd2f8 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java @@ -1782,6 +1782,93 @@ public void test047() { "----------\n" ); } +// 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<T> extends D<T> {\n" + + " public class A1 extends D1 {\n" + + " }\n" + + " void m1(A<T> tree) {\n" + + " A.A1 v = ((A.A1) tree.root);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class D<T> {\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; + this.runNegativeTest( + 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<T> {\n" + + " class Member {}\n" + + "}\n" + + "class Other2<T> extends Other<T> {\n" + + " class Member2<U> extends Other<U>.Member {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " Other<?>.Member m = (Other<?>.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Other2<?>.Member2<capture#1-of ?> to Other<?>.Member\n" + + "----------\n" + ); +} +// 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<T> extends D<T> {\n" + + " public class A1 extends D.D1 {\n" + + " }\n" + + " void m1(A<T> tree) {\n" + + " A.A1 v = ((A.A1) tree.root);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class D<T> {\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" + ); +} public static Class testClass() { return CastTest.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index 4e2023130..cebf4a207 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -190,9 +190,9 @@ public void test003_task_tags_options() { " }\n" + "}\n"}, null, - "[FIXME,message contents,HIGH]\n" + - "[TODO,message contents,NORMAL]\n" + - "[XXX,message contents,NORMAL]\n"); + "[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 @@ -208,9 +208,9 @@ public void _test004_task_tags_options() { " }\n" + "}\n"}, customOptions, - "[FIXME,message contents,NORMAL]\n" + - "[TODO,message contents,NORMAL]\n" + - "[XXX,message contents,NORMAL]\n"); + "[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 @@ -263,9 +263,9 @@ public void test007_task_tags_options() { " }\n" + "}\n"}, customOptions, - "[FIXME,message contents,NORMAL]\n" + - "[TODO,message contents,NORMAL]\n" + - "[XXX,message contents,NORMAL]\n"); + "[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 diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java index 2e03682ae..896383b6e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -1222,7 +1222,8 @@ public void test038() { "----------\n", null, true, - customOptions); + customOptions, + "java.lang.ClassNotFoundException"); } /* @@ -3194,7 +3195,11 @@ public void test099() { " 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" + "----------\n", + null, + true, + null, + "java.lang.ClassFormatError" // no compile errors but generates ClassFormatError if run ); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java index 7be85c0e0..5edd701db 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -1214,7 +1214,8 @@ public void test038() { "----------\n", null, true, - customOptions); + customOptions, + "java.lang.ClassNotFoundException"); } /* diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java index e32145a48..d2f1c7bee 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -1245,7 +1245,7 @@ public void test038() { "----------\n", // runtime results null /* do not check output string */, - null /* do not check error string */, + "java.lang.ClassNotFoundException" /* do not check error string */, // javac options JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java index 87f86d6d3..6da24bdd1 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java @@ -68,8 +68,8 @@ public void test002() { "class X {\n" + " String s2 = \"test1\"; //$NON-NLS-1$\n" + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + - " \n" + - " @SuppressWarnings(\"nls\")\n" + + "\n" + + "\n" + " void foo() {\n" + " String s4 = null;\n" + " String s5 = \"test3\";\n" + @@ -112,8 +112,8 @@ public void test003() { "class X {\n" + " String s2 = \"test1\"; //$NON-NLS-1$\n" + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + - " \n" + - " @SuppressWarnings(\"nls\")\n" + + "\n" + + "\n" + " void foo() {\n" + " String s4 = null;\n" + " String s5 = null;//$NON-NLS-1$\n" + @@ -184,7 +184,7 @@ public void test005() { new String[] { "X.java", "class X {\n" + - " @SuppressWarnings(\"nls\")\n" + + "\n" + " void foo() {\n" + " String s6 = \"SUCCESS\";\n" + " System.out.println(s6);\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java index eebfc9eb7..29e331575 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java @@ -19,7 +19,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class FieldAccessTest extends AbstractRegressionTest { static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 5, 6 }; +// TESTS_NUMBERS = new int[] { 21 }; // TESTS_RANGE = new int[] { 21, 50 }; } @@ -623,6 +623,32 @@ public void test020() { 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); +} public static Class testClass() { return FieldAccessTest.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java index 1888942b5..df86df560 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -32,7 +32,7 @@ public class GenericTypeTest extends AbstractComparableTest { // All specified tests which does not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test0788" }; -// TESTS_NUMBERS = new int[] { 1459 }; +// TESTS_NUMBERS = new int[] { 1455 }; // TESTS_RANGE = new int[] { 1097, -1 }; } public static Test suite() { @@ -2125,8 +2125,8 @@ public class GenericTypeTest extends AbstractComparableTest { "----------\n" + "1. ERROR in X.java (at line 9)\n" + " super(xt.t);\n" + - " ^^^^\n" + - "xt.t cannot be resolved or is not a field\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" + @@ -6468,7 +6468,7 @@ public class GenericTypeTest extends AbstractComparableTest { "----------\n", // runtime results null /* do not check output string */, - null /* do not check error string */, + "java.lang.IndexOutOfBoundsException" /* do not check error string */, // javac options JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); } @@ -14398,52 +14398,57 @@ public class GenericTypeTest extends AbstractComparableTest { " } \n" + "}\n" }, - "----------\n" + - "1. WARNING in test\\Foo.java (at line 4)\n" + - " private R dosomething(){ return s; } \n" + - " ^^^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo<R> is never used locally\n" + - "----------\n" + - "2. WARNING in test\\Foo.java (at line 5)\n" + - " private class Bar {} \n" + - " ^^^\n" + - "The type Foo<R>.Bar is never used locally\n" + - "----------\n" + - "----------\n" + - "1. ERROR in test02\\FooBar.java (at line 6)\n" + - " f.s = \"foo\"; \n" + - " ^\n" + - "The field Foo<String>.s is not visible\n" + - "----------\n" + - "2. ERROR in test02\\FooBar.java (at line 7)\n" + - " this.s = \"foo\";\n" + - " ^\n" + - "The field Foo<R>.s is not visible\n" + - "----------\n" + - "3. ERROR in test02\\FooBar.java (at line 8)\n" + - " f.dosomething(); \n" + - " ^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo<String> is not visible\n" + - "----------\n" + - "4. ERROR in test02\\FooBar.java (at line 9)\n" + - " this.dosomething(); \n" + - " ^^^^^^^^^^^\n" + - "The method dosomething() from the type Foo<R> is not visible\n" + - "----------\n" + - "5. ERROR in test02\\FooBar.java (at line 10)\n" + - " Bar b1; \n" + - " ^^^\n" + - "The type Bar is not visible\n" + - "----------\n" + - "6. ERROR in test02\\FooBar.java (at line 11)\n" + - " FooBar<String>.Bar b2; \n" + - " ^^^^^^^^^^^^^^^^^^\n" + - "The type FooBar.Bar is not visible\n" + - "----------\n" + - "7. ERROR in test02\\FooBar.java (at line 12)\n" + - " Foo<String>.Bar b3; \n" + - " ^^^^^^^^^^^^^^^\n" + - "The type Foo.Bar is not visible\n" + + "----------\n" + + "1. WARNING in test\\Foo.java (at line 4)\n" + + " private R dosomething(){ return s; } \n" + + " ^^^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo<R> is never used locally\n" + + "----------\n" + + "2. WARNING in test\\Foo.java (at line 5)\n" + + " private class Bar {} \n" + + " ^^^\n" + + "The type Foo<R>.Bar is never used locally\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test02\\FooBar.java (at line 6)\n" + + " f.s = \"foo\"; \n" + + " ^\n" + + "The field Foo<String>.s is not visible\n" + + "----------\n" + + "2. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^\n" + + "The field Foo<R>.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<String> 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<R> 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<String>.Bar b2; \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The type FooBar.Bar is not visible\n" + + "----------\n" + + "8. ERROR in test02\\FooBar.java (at line 12)\n" + + " Foo<String>.Bar b3; \n" + + " ^^^^^^^^^^^^^^^\n" + + "The type Foo.Bar is not visible\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 @@ -36688,8 +36693,8 @@ public void test1085() { "----------\n" + "7. ERROR in Y.java (at line 9)\n" + " E e2 = e2.e;\n" + - " ^^^^\n" + - "e2.e cannot be resolved or is not a field\n" + + " ^\n" + + "e cannot be resolved or is not a field\n" + "----------\n"); } @@ -45578,11 +45583,11 @@ public void test1336() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Other<String>.Member m = (Other<String>.Member) om2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Other2<?>.Member2<capture#1-of ?> to Other<String>.Member\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Other<String>.Member m = (Other<String>.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Other2<?>.Member2<capture#1-of ?> to Other<String>.Member\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation @@ -45603,11 +45608,11 @@ public void test1337() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " Other<String>.Member m = (Other<String>.Member) om2;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Cannot cast from Other2.Member2<capture#1-of ?> to Other<String>.Member\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Other<String>.Member m = (Other<String>.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Other2.Member2<capture#1-of ?> to Other<String>.Member\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 @@ -45667,10 +45672,11 @@ public void test1340() { 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<Object, Base_B> getMap() {\n" + - " return null;\n" + + " return new HashMap<Object, Base_B>();\n" + " }\n" + "}\n", // ================= "Derived_B.java", // ================= @@ -49797,8 +49803,8 @@ public void test1454() { public void test1455() { this.runNegativeTest( new String[] { - "X.java", - "class Outer<E> {\n" + + "Outer.java", + "public class Outer<E> {\n" + " Inner inner;\n" + " class Inner {\n" + " E e;\n" + @@ -49821,7 +49827,7 @@ public void test1455() { "}" }, "----------\n" + - "1. WARNING in X.java (at line 8)\n" + + "1. WARNING in Outer.java (at line 8)\n" + " Inner that = (Inner) other;\n" + " ^^^^^^^^^^^^^\n" + "Type safety: Unchecked cast from Object to Outer<E>.Inner\n" + @@ -50089,4 +50095,64 @@ public void test294724() { "Type safety: The expression of type Set needs unchecked conversion to conform to Set<SimpleExample.Data>\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798 +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<A> 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<T> 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<GenericDemo.A>) of the generic method min(Collection<? extends T>) of type Collections\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798 +public void test268798a() { + this.runNegativeTest( + new String[] { + "Bug268798.java", + "public class Bug268798 {\n" + + " interface SomeInterface<T> {\n" + + " }\n" + + " class A implements SomeInterface {\n" + + " }\n" + + " <T extends SomeInterface<? super T>> 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<T> 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"); +} }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java index 761c7481f..a8adfa082 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java @@ -25,7 +25,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class InnerEmulationTest extends AbstractRegressionTest { static { // TESTS_NAMES = new String[] { "Bug58069" }; -// TESTS_NUMBERS = new int[] { 155 }; +// TESTS_NUMBERS = new int[] { 23, 24 }; // TESTS_RANGE = new int[] { 144, -1 }; } public InnerEmulationTest(String name) { @@ -1001,10 +1001,11 @@ public void test022() { * No need for protected access emulation */ public void test023() { - this.runNegativeTest( + 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" + @@ -1019,14 +1020,14 @@ public void test023() { " protected Object someObject; \n" + "}\n" }, - "" // no problem log: not even a synthetic access emulation one + "SUCCESS" ); } /** * No need for protected access emulation */ public void test024() { - this.runNegativeTest( + this.runConformTest( new String[] { /* X.java */ "p/X.java", @@ -1045,7 +1046,7 @@ public void test024() { " protected Object foo(){ return null;} \n" + "}\n" }, - "" // no problem log: not even a synthetic access emulation one + "SUCCESS" ); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java index 0607e8168..6234f5a4f 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java @@ -6408,7 +6408,7 @@ public void testBug170637() { this.reportMissingJavadocTags = CompilerOptions.ERROR; runConformTest( new String[] { - "src/JavaDocTest.java", + "JavaDocTest.java", "public interface JavaDocTest\n" + "{\n" + " /**\n" + @@ -7174,7 +7174,7 @@ public void testBug190970a() { this.runConformTest( true, new String[] { - "pkg/X.java", + "X.java", "public class X {\n" + "private int unused1;\n" + "\n" + @@ -7187,12 +7187,12 @@ public void testBug190970a() { null, customOptions, "----------\n" + - "1. WARNING in pkg\\X.java (at line 2)\n" + + "1. WARNING in X.java (at line 2)\n" + " private int unused1;\n" + " ^^^^^^^\n" + "The field X.unused1 is never read locally\n" + "----------\n" + - "2. WARNING in pkg\\X.java (at line 7)\n" + + "2. WARNING in X.java (at line 7)\n" + " private int unused2;\n" + " ^^^^^^^\n" + "The field X.unused2 is never read locally\n" + @@ -7949,7 +7949,7 @@ public void testBug233887() { public void testBug237937() { runConformTest( new String[] { - "src/Link.java", + "Link.java", "/**\n" + " * @see <a href=\"http://www.eclipse.org/\">http://www.eclipse.org</a>\n" + " * @see <a href=\"http://www.eclipse.org/\">//</a>\n" + @@ -7968,7 +7968,7 @@ public void testBug246712() { this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; runConformTest( new String[] { - "src/X.java", + "X.java", "public class X {\n" + "\n" + " /**\n" + @@ -7981,7 +7981,7 @@ public void testBug246712() { " return \"X\";\n" + " }\n" + "}\n", - "src/Y.java", + "Y.java", "public class Y extends X {\n" + "\n" + " /**\n" + @@ -8003,7 +8003,7 @@ public void testBug246712b() { this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; runConformTest( new String[] { - "src/X.java", + "X.java", "/**\n" + " * @author {@link String}\n" + " * @since {@link String}\n" + @@ -8033,7 +8033,7 @@ public void testBug246715() { this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; runConformTest( new String[] { - "src/X.java", + "X.java", "public class X {\n" + "\n" + " final static int WAIT_YES = 0;\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java index 703a2bf2c..73537bd9c 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java @@ -458,7 +458,6 @@ public abstract class JavadocTest extends AbstractRegressionTest { boolean shouldFlushOutputDirectory) { String testName = null; Process compileProcess = null; - Process execProcess = null; try { // Init test name testName = testName(); @@ -589,7 +588,6 @@ public abstract class JavadocTest extends AbstractRegressionTest { } catch (InterruptedException e1) { if (compileProcess != null) compileProcess.destroy(); - if (execProcess != null) execProcess.destroy(); System.out.println(testName+": Sun javadoc compilation was aborted!"); javacFullLog.println("JAVAC_WARNING: Sun javadoc compilation was aborted!"); e1.printStackTrace(javacFullLog); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java index c48bdff35..5ff18a81e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -216,15 +216,15 @@ public void test006() { "}" }, "----------\n" + - "1. WARNING in p1\\A.java (at line 3)\n" + - " private static String success = \"SUCCESS\"; \n" + - " ^^^^^^^\n" + - "The field A.success is never read locally\n" + - "----------\n" + - "2. ERROR in p1\\A.java (at line 7)\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"); } /** @@ -308,12 +308,7 @@ public void test009() { "}" }, "----------\n" + - "1. WARNING in p1\\A.java (at line 3)\n" + - " private String success = \"SUCCESS\"; \n" + - " ^^^^^^^\n" + - "The field A.success is never read locally\n" + - "----------\n" + - "2. ERROR in p1\\A.java (at line 7)\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" + @@ -656,8 +651,8 @@ public void test019() { "----------\n" + "1. ERROR in p1\\A.java (at line 17)\n" + " System.out.println(foo.rating + bar.other); \n" + - " ^^^^^^^^^\n" + - "bar.other cannot be resolved or is not a field\n" + + " ^^^^^\n" + + "other cannot be resolved or is not a field\n" + "----------\n" ); } @@ -693,8 +688,8 @@ public void test020() { "----------\n" + "2. ERROR in p1\\A.java (at line 13)\n" + " System.out.println(foo.rating + bar.other); \n" + - " ^^^^^^^^^\n" + - "bar.other cannot be resolved or is not a field\n" + + " ^^^^^\n" + + "other cannot be resolved or is not a field\n" + "----------\n"); } /** @@ -2891,8 +2886,8 @@ public void test086() { "----------\n" + "1. ERROR in X.java (at line 5)\n" + " System.out.println(y.length);\n" + - " ^^^^^^^^\n" + - "y.length cannot be resolved or is not a field\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java index 7ef848eeb..08116c580 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class MethodVerifyTest extends AbstractComparableTest { static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 121 }; +// TESTS_NUMBERS = new int[] { 184 }; // TESTS_RANGE = new int[] { 190, -1}; } @@ -8088,7 +8088,11 @@ public void test127() { " 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<T>\n" + - "----------\n"); + "----------\n", + null, + true, + null, + "java.lang.ClassCastException"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 public void test128() { @@ -8275,7 +8279,7 @@ public void test133() { public void test134() { this.runNegativeTest( new String[] { - "X.java", + "A.java", "interface I {\n" + " <T extends Exception & Cloneable> T foo(Number n);\n" + "}\n" + @@ -8287,7 +8291,7 @@ public void test134() { "}" }, "----------\n" + - "1. WARNING in X.java (at line 5)\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" + @@ -10015,7 +10019,7 @@ public void test183() { public void test184() { this.runNegativeTest( new String[] { - "X.java", + "A.java", "class A<U extends Number> {\n" + " <T extends A<Number>> T a() { return null; }\n" + " <T extends Number> U num() { return null; }\n" + @@ -10047,42 +10051,42 @@ public void test184() { "}" }, "----------\n" + - "1. WARNING in X.java (at line 6)\n" + + "1. WARNING in A.java (at line 6)\n" + " <T extends Integer> 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 X.java (at line 9)\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<U> should be parameterized\n" + "----------\n" + - "3. WARNING in X.java (at line 9)\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<U>\n" + "----------\n" + - "4. WARNING in X.java (at line 11)\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<U>\n" + "----------\n" + - "5. WARNING in X.java (at line 12)\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<U>\n" + "----------\n" + - "6. WARNING in X.java (at line 13)\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<U>\n" + "----------\n" + - "7. WARNING in X.java (at line 15)\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<U> should be parameterized\n" + "----------\n" + - "8. WARNING in X.java (at line 16)\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<U> should be parameterized\n" + @@ -10731,4 +10735,101 @@ public void test204a() { "Name clash: The method put(K, V) of type OverrideBug<K,V> has the same erasure as put(K, V) of type Map<K,V> 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<T> {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter<T extends Enum<T>> implements Converter<Enum<T>> {\n" + + " public final T convert(String input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter<Thread.State> {\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<T> {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter<T extends Enum<T>> implements Converter<T> {\n" + + " public final T convert(String input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter<Thread.State> {\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<T> {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter<T extends Enum<T>, K> implements Converter<T> {\n" + + " public final T convert(K input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter<Thread.State, String> {\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"); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java index ddd34e05b..33247b296 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java @@ -10,10 +10,14 @@ *******************************************************************************/ 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; @@ -22,29 +26,25 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class NullReferenceTest extends AbstractRegressionTest { public NullReferenceTest(String name) { - super(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" }; -// TESTS_NUMBERS = new int[] { 561 }; -// TESTS_NUMBERS = new int[] { 2999 }; -// TESTS_RANGE = new int[] { 2050, -1 }; -// TESTS_RANGE = new int[] { 1, 2049 }; -// TESTS_RANGE = new int[] { 449, 451 }; -// TESTS_RANGE = new int[] { 900, 999 }; - } +// 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[] { "testBug304416" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +} public static Test suite() { - return buildAllCompliancesTestSuite(testClass()); + return buildAllCompliancesTestSuite(testClass()); } public static Class testClass() { - return NullReferenceTest.class; + return NullReferenceTest.class; } // Conditionally augment problem detection settings @@ -4133,8 +4133,8 @@ public void test0459_while_nested() { " }\n" + "}\n"}, "----------\n" + - "1. ERROR in X.java (at line 11)\r\n" + - " while (o == null) {\r\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", @@ -5177,8 +5177,8 @@ public void test0525_try_finally_unchecked_exception() { " }\n" + "}"}, "----------\n" + - "1. ERROR in X.java (at line 13)\r\n" + - " o.toString();\r\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", @@ -6054,7 +6054,157 @@ public void test0568_try_catch_checked_exception() { }, ""); } - +// 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"); +} // null analysis - throw // https://bugs.eclipse.org/bugs/show_bug.cgi?id=201182 public void test0595_throw() { @@ -8082,12 +8232,7 @@ public void test0953_assert_combined() { " ^^\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" + + "2. 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" + @@ -8136,11 +8281,6 @@ public void test0955_assert_combined() { " 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); } @@ -8156,25 +8296,258 @@ public void test0956_assert_combined() { "public class X {\n" + " void foo() {\n" + " Object o = null;\n" + - " assert(o != null);\n" + // complain + " assert(o != null);\n" + // don't 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" + + "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); + } +} + +// 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 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" + - "3. WARNING in X.java (at line 5)\n" + - " if (o == null) { };\n" + - " ^^^\n" + - "Dead code\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. 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" + + "3. 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" + + "4. 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", + 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<Integer,X> map = new HashMap<Integer,X>();\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 null comparison 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. 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" + + "3. 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" + + "4. 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", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from null comparison 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. 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" + + "3. 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" + + "4. 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", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from null comparison 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. 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" + + "3. 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" + + "4. 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", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -8697,17 +9070,17 @@ public void test1018() { " }\n" + "}"}, "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " if (o != null) return;\r\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)\r\n" + - " o = null;\r\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); + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } public void test1019() { @@ -10753,4 +11126,514 @@ public void testBug299900b() { "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) { + this.runNegativeTest( + 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: The variable f1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: The variable f2 can only be null at this location\n" + + "----------\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) { + this.runNegativeTest( + 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: The variable i1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if(i1 == 0) {}\n" + + " ^^\n" + + "Potential null pointer access: The variable i1 may be null at this location\n" + + "----------\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) { + this.runNegativeTest( + 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: The variable f1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: The variable f2 can only be null at this location\n" + + "----------\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: The variable a can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " if(outer2 == 1) {}\n" + + " ^^^^^^\n" + + "Potential null pointer access: The variable outer2 may be null at this location\n" + + "----------\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) { + this.runNegativeTest( + 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: The variable f1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: The variable f2 can only be null at this location\n" + + "----------\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: The variable outer can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 19)\n" + + " if(param == 1) {}\n" + + " ^^^^^\n" + + "Potential null pointer access: The variable param may be null at this location\n" + + "----------\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 <String \"foo is not null\"> [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 <String \"foo is null\"> [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 <String \"foo2 is not null\"> [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 <String \"foo2 is null\"> [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: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\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 <String \"foo is not null\"> [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 <String \"foo is null\"> [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 <String \"foo2 is not null\"> [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 <String \"foo2 is null\"> [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: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\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 <String \"foo is not null\"> [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 <String \"foo is null\"> [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 <String \"foo2 is not null\"> [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 <String \"foo2 is null\"> [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: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\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 12\n" + + " 8 aload_2 [s2]\n" + + " 9 ifnull 12\n" + + " 12 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java index 2421301c5..5e565463e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java @@ -1559,4 +1559,65 @@ public void test0040() { "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 */); +} }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java index 8bd47ad43..0b4c1d548 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java @@ -2485,8 +2485,8 @@ public class StaticImportTest extends AbstractComparableTest { "----------\n" + "1. ERROR in p1\\A.java (at line 7)\n" + " int v2 = b.fooC;\n" + - " ^^^^^^\n" + - "b.fooC cannot be resolved or is not a field\n" + + " ^^^^\n" + + "fooC cannot be resolved or is not a field\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375 diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java index 73c61957a..e9b779d2a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java @@ -16,6 +16,7 @@ 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; @@ -106,6 +107,7 @@ public static Test suite() { // Build final test suite TestSuite all = new TestSuite(TestAll.class.getName()); + all.addTest(new TestSuite(StandAloneASTParserTest.class)); int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) { ArrayList tests_1_3 = (ArrayList)standardTests.clone(); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java index 049c13ecf..ea958f997 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java @@ -21,6 +21,7 @@ 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; @@ -772,7 +773,7 @@ public void test018() throws Exception { * 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 { +public void test019() throws Exception { try { String sourceA019 = "public class A019 {\n" + @@ -798,10 +799,10 @@ public void _test019() throws Exception { 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()); + 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"); } @@ -2939,6 +2940,121 @@ public void test067() { 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 <U> 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 <U> 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.<Object>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); + } + 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", 31, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask); + 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 */ diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java index 098b23f90..7886745f4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -130,7 +130,7 @@ public void testInvalidField() { evaluateWithExpectedProblem( ("String s = \"\";\n" + "s.length").toCharArray(), - "s.length cannot be resolved or is not a field\n"); + "length cannot be resolved or is not a field\n"); } /** * Test a code snippet which is valid but the evaluation context imports have problems. diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java index 38b392069..e46b21240 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java @@ -647,31 +647,32 @@ private static File createMemLogFile() { } // Get file (create if necessary) File logFile = new File(MEM_LOG_DIR, STORE_MEMORY+".log"); + PrintStream stream = null; try { boolean fileExist = logFile.exists(); - PrintStream stream = new PrintStream(new FileOutputStream(logFile, true)); - if (stream != null) { - if (fileExist) { - stream.println(); - } - // Log date and time - Date date = new Date(System.currentTimeMillis()); - stream.println("Tests:\t" + STORE_MEMORY); - stream.println("Date:\t" + DateFormat.getDateInstance(3).format(date)); - stream.println("Time:\t" + DateFormat.getTimeInstance(3).format(date)); - // Log columns title - stream.print("Class"); - if (ALL_TESTS_LOG) stream.print("\tTest"); - stream.print("\tUsed\tTotal\tMax"); + stream = new PrintStream(new FileOutputStream(logFile, true)); + if (fileExist) { stream.println(); - stream.close(); - System.out.println("Log file " + logFile.getPath() + " opened."); - return logFile; - } else { - System.err.println("Cannot open file " + logFile.getPath()); } + // Log date and time + Date date = new Date(System.currentTimeMillis()); + stream.println("Tests:\t" + STORE_MEMORY); + stream.println("Date:\t" + DateFormat.getDateInstance(3).format(date)); + stream.println("Time:\t" + DateFormat.getTimeInstance(3).format(date)); + // Log columns title + stream.print("Class"); + if (ALL_TESTS_LOG) stream.print("\tTest"); + stream.print("\tUsed\tTotal\tMax"); + stream.println(); + System.out.println("Log file " + logFile.getPath() + " opened."); + return logFile; } catch (FileNotFoundException e) { // no log available for this statistic + System.err.println("Cannot open file " + logFile.getPath()); + } finally { + if (stream != null) { + stream.close(); + } } return null; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java index 246af066c..8c38c58d1 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -49,8 +49,9 @@ private boolean checkBuffers(String outputString, String errorString, didMatchExpectation = false; } } + String trimmedErrorString = errorString.trim(); if (expectedErrorStringStart != null) { - platformIndependantString = Util.convertToIndependantLineDelimiter(errorString.trim()); + platformIndependantString = Util.convertToIndependantLineDelimiter(trimmedErrorString); if (expectedErrorStringStart.length() == 0 && platformIndependantString.length() > 0 || !platformIndependantString.startsWith(Util.convertToIndependantLineDelimiter(expectedErrorStringStart))) { /* @@ -71,6 +72,17 @@ private boolean checkBuffers(String outputString, String 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; } @@ -387,7 +399,7 @@ private void launchAndRun(String className, String[] classpaths, String[] progra TestVerifier.this.outputBuffer.append((char) c); c = input.read(); } - } catch(IOException ioEx) { + } catch(IOException e) { } } }); @@ -400,7 +412,7 @@ private void launchAndRun(String className, String[] classpaths, String[] progra TestVerifier.this.errorBuffer.append((char) c); c = errorStream.read(); } - } catch(IOException ioEx) { + } catch(IOException e) { } } }); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java index 569c47b1a..5a659373d 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -213,9 +213,14 @@ public void run() throws IOException { System.out.println(VerifyTests.class.getName()); out.writeBoolean(false); } catch (IOException e1) { - // ignore + e1.printStackTrace(); } } + try { + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } } }; thread.start(); |