summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorManoj Palat2012-10-16 05:06:03 (EDT)
committer Srikanth2012-10-16 05:06:03 (EDT)
commitb628aba2a04b266a91b77953499d95be31cca064 (patch)
treef666e2782fb873c1d43d6813a6735f8d1ad20147
parent363f295181efb5d08470dfb8bacfcdd493852030 (diff)
downloadeclipse.jdt.core-b628aba2a04b266a91b77953499d95be31cca064.zip
eclipse.jdt.core-b628aba2a04b266a91b77953499d95be31cca064.tar.gz
eclipse.jdt.core-b628aba2a04b266a91b77953499d95be31cca064.tar.bz2
Fixed bug 391092: [1.7][compiler] ECJ accepts invalid union typev20121016-090603I20121016-2240I20121016-0800
reference
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java49
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties3
6 files changed, 69 insertions, 0 deletions
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 f87f753..f721bb6 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
@@ -938,6 +938,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("WildcardConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("WildcardFieldAssignment", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("WildcardMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
+ expectedProblemAttributes.put("IllegalArrayOfUnionType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -1644,6 +1645,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("WildcardConstructorInvocation", SKIP);
expectedProblemAttributes.put("WildcardFieldAssignment", SKIP);
expectedProblemAttributes.put("WildcardMethodInvocation", SKIP);
+ expectedProblemAttributes.put("IllegalArrayOfUnionType", SKIP);
Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java
index ba8feb8..fafc9d3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java
@@ -1167,6 +1167,55 @@ public void test032() { // no finally
},
"Done");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
+public void testBug391092() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " try {\n" +
+ " } catch (NullPointerException | ArrayIndexOutOfBoundsException e []) {\n" +
+ " } catch (ClassCastException [] c) {\n" +
+ " } catch (ArrayStoreException a[]) {\n" +
+ " } catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" +
+ " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " } catch (NullPointerException | ArrayIndexOutOfBoundsException e []) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal attempt to create arrays of union types\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 5)\n" +
+ " } catch (ClassCastException [] c) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "No exception of type ClassCastException[] can be thrown; an exception type must be a subclass of Throwable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 6)\n" +
+ " } catch (ArrayStoreException a[]) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "No exception of type ArrayStoreException[] can be thrown; an exception type must be a subclass of Throwable\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 7)\n" +
+ " } catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Illegal attempt to create arrays of union types\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 8)\n" +
+ " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "No exception of type ClassCastException[][] can be thrown; an exception type must be a subclass of Throwable\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 8)\n" +
+ " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "No exception of type ClassNotFoundException[] can be thrown; an exception type must be a subclass of Throwable\n" +
+ "----------\n");
+ }
public static Class testClass() {
return TryStatement17Test.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 9dfff59..ca03e0c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1295,6 +1295,8 @@ void setSourceStart(int sourceStart);
int UnusedTypeArgumentsForConstructorInvocation = MethodRelated + 660;
/** @since 3.9 */
int UnusedTypeParameter = TypeRelated + 661;
+ /** @since 3.9 */
+ int IllegalArrayOfUnionType = TypeRelated + 662;
/**
* Corrupted binaries
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 3f50e7a..90887c1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -2154,6 +2154,10 @@ protected void consumeCatchFormalParameter() {
if (extendedDimensions > 0) {
type = type.copyDims(type.dimensions() + extendedDimensions);
type.sourceEnd = this.endPosition;
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
+ if (type instanceof UnionTypeReference) {
+ this.problemReporter().illegalArrayOfUnionType(identifierName, type);
+ }
}
this.astLengthPtr--;
int modifierPositions = this.intStack[this.intPtr--];
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index a901cd4..f03d22a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -1219,6 +1219,15 @@ public void cannotThrowType(ASTNode exception, TypeBinding expectedType) {
exception.sourceStart,
exception.sourceEnd);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
+public void illegalArrayOfUnionType(char[] identifierName, TypeReference typeReference) {
+ this.handle(
+ IProblem.IllegalArrayOfUnionType,
+ NoArgument,
+ NoArgument,
+ typeReference.sourceStart,
+ typeReference.sourceEnd);
+}
public void cannotUseQualifiedEnumConstantInCaseLabel(Reference location, FieldBinding field) {
this.handle(
IProblem.IllegalQualifiedEnumConstantLabel,
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 0d57bd6..70e0902 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -586,6 +586,9 @@
660 = Unused type arguments for the non generic constructor {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
661 = Unused type parameter {0}
+### MORE TYPE RELATED
+662 = Illegal attempt to create arrays of union types
+
### CORRUPTED BINARIES
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}