diff options
author | Olivier Thomann | 2005-11-03 16:56:26 +0000 |
---|---|---|
committer | Olivier Thomann | 2005-11-03 16:56:26 +0000 |
commit | ab9f6af2838e24ba64bcda024fa53e8f20f3cd4f (patch) | |
tree | 0d4624da35df8127fabfd6c5393f9f13f6fcb538 | |
parent | 8b135df1c3a933bdb901f9ba445f12e53b140a6b (diff) | |
download | eclipse.jdt.core-ab9f6af2838e24ba64bcda024fa53e8f20f3cd4f.tar.gz eclipse.jdt.core-ab9f6af2838e24ba64bcda024fa53e8f20f3cd4f.tar.xz eclipse.jdt.core-ab9f6af2838e24ba64bcda024fa53e8f20f3cd4f.zip |
3.1 maintenance - Fix for 114855
3 files changed, 288 insertions, 15 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java index 0786bb906b..fd45be2c76 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java @@ -1083,6 +1083,233 @@ public void test030() { }, "EXCEPTION:ONCE:SUCCESS"); } +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=114855 + */ +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " static int except_count;\n" + + "\n" + + " static boolean test_result = true;\n" + + " \n" + + " static Throwable all_except[] =\n" + + " {\n" + + " new AbstractMethodError(), // 0\n" + + " new ArithmeticException(), // 1\n" + + " new ArrayIndexOutOfBoundsException(), // 2\n" + + " new ArrayStoreException(), // 3\n" + + " new ClassCastException(), // 4\n" + + " new ClassCircularityError(), // 5\n" + + " new ClassFormatError(), // 6\n" + + " new ClassNotFoundException(), // 7\n" + + " new CloneNotSupportedException(), // 8\n" + + " new Error(), // 9\n" + + " new Exception(), // 10\n" + + " new IllegalAccessError(), // 11\n" + + " new IllegalAccessException(), // 12\n" + + " new IllegalArgumentException(), // 13\n" + + " new IllegalMonitorStateException(), // 14\n" + + " new IllegalThreadStateException(), // 15\n" + + " new IncompatibleClassChangeError(), // 16\n" + + " new IndexOutOfBoundsException(), // 17\n" + + " new InstantiationError(), // 18\n" + + " new InstantiationException(), // 19\n" + + " new InternalError(), // 20\n" + + " new InterruptedException(), // 21\n" + + " new LinkageError(), // 22\n" + + " new NegativeArraySizeException(), // 23\n" + + " new NoClassDefFoundError(), // 24\n" + + " new NoSuchFieldError(), // 25\n" + + " new NoSuchMethodError(), // 26\n" + + " new NoSuchMethodException(), // 27\n" + + " new NullPointerException(), // 28\n" + + " new NumberFormatException(), // 29\n" + + " new OutOfMemoryError(), // 30\n" + + " new StackOverflowError(), // 31\n" + + " new RuntimeException(), // 32\n" + + " new SecurityException(), // 33\n" + + " new StringIndexOutOfBoundsException(), // 34\n" + + " new ThreadDeath(), // 35\n" + + " new UnknownError(), // 36\n" + + " new UnsatisfiedLinkError(), // 37\n" + + " new VerifyError(), // 38\n" + + " };\n" + + "\n" + + " private static void check_except(int i)\n" + + " throws Throwable\n" + + " {\n" + + " if (except_count != i)\n" + + " {\n" + + " System.out.println(\"Error \"+except_count+\" != \"+i+\";\");\n" + + " test_result=false;\n" + + " }\n" + + " throw all_except[++except_count];\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Throwable\n" + + " {\n" + + " try {\n" + + " except_count = 0;\n" + + " throw all_except[except_count];\n" + + " } catch (AbstractMethodError e0) {\n" + + " try {\n" + + " check_except(0);\n" + + " } catch (ArithmeticException e1) {\n" + + " try {\n" + + " check_except(1);\n" + + " } catch (ArrayIndexOutOfBoundsException e2) {\n" + + " try {\n" + + " check_except(2);\n" + + " } catch (ArrayStoreException e3) {\n" + + " try {\n" + + " check_except(3);\n" + + " } catch (ClassCastException e4) {\n" + + " try {\n" + + " check_except(4);\n" + + " } catch (ClassCircularityError e5) {\n" + + " try {\n" + + " check_except(5);\n" + + " } catch (ClassFormatError e6) {\n" + + " try {\n" + + " check_except(6);\n" + + " } catch (ClassNotFoundException e7) {\n" + + " try {\n" + + " check_except(7);\n" + + " } catch (CloneNotSupportedException e8) {\n" + + " try {\n" + + " check_except(8);\n" + + " } catch (Error e9) {\n" + + " try {\n" + + " check_except(9);\n" + + " } catch (Exception e10) {\n" + + " try {\n" + + " check_except(10);\n" + + " } catch (IllegalAccessError e11) {\n" + + " try {\n" + + " check_except(11);\n" + + " } catch (IllegalAccessException e12) {\n" + + " try {\n" + + " check_except(12);\n" + + " } catch (IllegalArgumentException e13) {\n" + + " try {\n" + + " check_except(13);\n" + + " } catch (IllegalMonitorStateException e14) {\n" + + " try {\n" + + " check_except(14);\n" + + " } catch (IllegalThreadStateException e15) {\n" + + " try {\n" + + " check_except(15);\n" + + " } catch (IncompatibleClassChangeError e16) {\n" + + " try {\n" + + " check_except(16);\n" + + " } catch (IndexOutOfBoundsException e17) {\n" + + " try {\n" + + " check_except(17);\n" + + " } catch (InstantiationError e18) {\n" + + " try {\n" + + " check_except(18);\n" + + " } catch (InstantiationException e19) {\n" + + " try {\n" + + " check_except(19);\n" + + " } catch (InternalError e20) {\n" + + " try {\n" + + " check_except(20);\n" + + " } catch (InterruptedException \n" + + "e21) {\n" + + " try {\n" + + " check_except(21);\n" + + " } catch (LinkageError e22) {\n" + + " try {\n" + + " check_except(22);\n" + + " } catch \n" + + "(NegativeArraySizeException e23) {\n" + + " try {\n" + + " check_except(23);\n" + + " } catch \n" + + "(NoClassDefFoundError e24) {\n" + + " try {\n" + + " check_except(24);\n" + + " } catch (NoSuchFieldError \n" + + "e25) {\n" + + " try {\n" + + " check_except(25);\n" + + " } catch \n" + + "(NoSuchMethodError e26) {\n" + + " try {\n" + + " check_except(26);\n" + + " } catch \n" + + "(NoSuchMethodException e27) {\n" + + " try {\n" + + " check_except(27);\n" + + " } catch \n" + + "(NullPointerException e28) {\n" + + " try {\n" + + " check_except\n" + + "(28);\n" + + " } catch \n" + + "(NumberFormatException e29) {\n" + + " try {\n" + + " check_except\n" + + "(29);\n" + + " } catch \n" + + "(OutOfMemoryError e30) {\n" + + " try {\n" + + " check_except\n" + + "(30);\n" + + " } catch \n" + + "(StackOverflowError e31) {\n" + + " try {\n" + + " \n" + + "check_except(31);\n" + + " } catch \n" + + "(RuntimeException e32) {\n" + + " try {\n" + + " \n" + + "check_except(32);\n" + + " } catch \n" + + "(SecurityException e33) {\n" + + " try {\n" + + " \n" + + "check_except(33);\n" + + " } catch \n" + + "(StringIndexOutOfBoundsException e34) {\n" + + " try {\n" + + " \n" + + "check_except(34);\n" + + " } \n" + + "catch (ThreadDeath e35) {\n" + + " try \n" + + "{\n" + + " \n" + + "check_except(35);\n" + + " } \n" + + "catch (UnknownError e36) {\n" + + " \n" + + "try {\n" + + " \n" + + "check_except(36);\n" + + " } \n" + + "catch (UnsatisfiedLinkError e37) {\n" + + " \n" + + "try {\n" + + " \n" + + " check_except(37);\n" + + " \n" + + "} catch (VerifyError e38) {\n" + + " \n" + + " ++except_count;\n" + + " \n" + + "}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}\n" + + " System.out.print(test_result & (except_count == all_except.length));\n" + + " }\n" + + "}", + }, + "true"); +} public static Class testClass() { return TryStatementTest.class; } diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html index 2c595b0fda..c5c980fa7d 100644 --- a/org.eclipse.jdt.core/buildnotes_jdt-core.html +++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html @@ -53,7 +53,9 @@ it was "X$2" before 5.0.</li> </ul> <h3>Problem Reports Fixed</h3> -<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=114304">114304</a> +<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=114855">114855</a> +[compiler] OutOfMemoryError compiling deeply nested try-catch +<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=114304">114304</a> [1.5][compiler] Return type not compatible with generic subinterface. <br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=112109">112109</a> Compilation problem: Eclipse does not recognise parametrized notify-method in generic context diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/Label.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/Label.java index c286bdcae5..e0314b5b42 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/Label.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/Label.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.codegen; +import java.util.Arrays; + import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; import org.eclipse.jdt.internal.compiler.problem.AbortMethod; @@ -36,26 +38,68 @@ public Label(CodeStream codeStream) { /** * Add a forward refrence for the array. */ -void addForwardReference(int iPos) { - int length; - if (forwardReferenceCount >= (length = forwardReferences.length)) - System.arraycopy(forwardReferences, 0, (forwardReferences = new int[2*length]), 0, length); - forwardReferences[forwardReferenceCount++] = iPos; +void addForwardReference(int pos) { + final int count = this.forwardReferenceCount; + if (count >= 1) { + int previousValue = this.forwardReferences[count - 1]; + if (previousValue < pos) { + int length; + if (count >= (length = this.forwardReferences.length)) + System.arraycopy(this.forwardReferences, 0, (this.forwardReferences = new int[2*length]), 0, length); + this.forwardReferences[this.forwardReferenceCount++] = pos; + } else if (previousValue > pos) { + int[] refs = this.forwardReferences; + // check for duplicates + for (int i = 0, max = this.forwardReferenceCount; i < max; i++) { + if (refs[i] == pos) return; // already recorded + } + int length; + if (count >= (length = refs.length)) + System.arraycopy(refs, 0, (this.forwardReferences = new int[2*length]), 0, length); + this.forwardReferences[this.forwardReferenceCount++] = pos; + Arrays.sort(this.forwardReferences, 0, this.forwardReferenceCount); + } + } else { + int length; + if (count >= (length = this.forwardReferences.length)) + System.arraycopy(this.forwardReferences, 0, (this.forwardReferences = new int[2*length]), 0, length); + this.forwardReferences[this.forwardReferenceCount++] = pos; + } } /** * Add a forward refrence for the array. */ public void appendForwardReferencesFrom(Label otherLabel) { - int otherCount = otherLabel.forwardReferenceCount; + final int otherCount = otherLabel.forwardReferenceCount; if (otherCount == 0) return; - int length = forwardReferences.length; - int neededSpace = otherCount + forwardReferenceCount; - if (neededSpace >= length){ - System.arraycopy(forwardReferences, 0, (forwardReferences = new int[neededSpace]), 0, forwardReferenceCount); + // need to merge the two sorted arrays of forward references + int[] mergedForwardReferences = new int[this.forwardReferenceCount + otherCount]; + int indexInMerge = 0; + int j = 0; + int i = 0; + int max = this.forwardReferenceCount; + int max2 = otherLabel.forwardReferenceCount; + loop1 : for (; i < max; i++) { + final int value1 = this.forwardReferences[i]; + for (; j < max2; j++) { + final int value2 = otherLabel.forwardReferences[j]; + if (value1 < value2) { + mergedForwardReferences[indexInMerge++] = value1; + continue loop1; + } else if (value1 == value2) { + mergedForwardReferences[indexInMerge++] = value1; + j++; + continue loop1; + } else { + mergedForwardReferences[indexInMerge++] = value2; + } + } + } + for (; j < max2; j++) { + mergedForwardReferences[indexInMerge++] = otherLabel.forwardReferences[j]; } - // append other forward references at the end, so they will get updated as well - System.arraycopy(otherLabel.forwardReferences, 0, forwardReferences, forwardReferenceCount, otherCount); - forwardReferenceCount = neededSpace; + this.forwardReferences = mergedForwardReferences; + this.forwardReferenceCount = indexInMerge; } /* * Put down a reference to the array at the location in the codestream. @@ -157,7 +201,7 @@ public void place() { // Currently lacking wide support. codeStream.classFileOffset -= 3; forwardReferenceCount--; // also update the PCs in the related debug attributes - /** OLD CODE + /* OLD CODE int index = codeStream.pcToSourceMapSize - 1; while ((index >= 0) && (codeStream.pcToSourceMap[index][1] == oldPosition)) { codeStream.pcToSourceMap[index--][1] = position; |