aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2012-10-18 14:23:01 (EDT)
committerJayaprakash Arthanareeswaran2012-10-19 00:49:09 (EDT)
commit82fb0988aac42c539d857c6e76c63851f3e39e4a (patch)
treef3010178fce0d54348cff45b15015a316477bc77
parentf7ea870ffaddfcb451c55807a166c8c5500cf565 (diff)
downloadeclipse.jdt.core-82fb0988aac42c539d857c6e76c63851f3e39e4a.zip
eclipse.jdt.core-82fb0988aac42c539d857c6e76c63851f3e39e4a.tar.gz
eclipse.jdt.core-82fb0988aac42c539d857c6e76c63851f3e39e4a.tar.bz2
Fixed bug 391092: [1.7][compiler] ECJ accepts invalid union type
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 1553b5e..5333b1b 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
@@ -965,6 +965,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();
@@ -1692,6 +1693,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("WildcardFieldAssignment", SKIP);
expectedProblemAttributes.put("WildcardMethodInvocation", SKIP);
expectedProblemAttributes.put("DisallowedExplicitThisParameter", 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 95aab42..ca3b4b5 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
@@ -1331,6 +1331,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 e06e839..86ea73e 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
@@ -2335,6 +2335,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 61b1110..ec6046e 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
@@ -1228,6 +1228,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 d69a6dc..0d765d9 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
@@ -607,6 +607,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}