Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2020-07-29 16:14:18 +0000
committerJay Arthanareeswaran2020-07-30 10:39:27 +0000
commit75b0a2076e14e6a434336ad66b8b7be81f69eddb (patch)
tree6c851b45da2ad1d146dc18de8a3fc540607358c6
parent5f22973b8ab9d4b000a76fd2f78e45801b306123 (diff)
downloadeclipse.jdt.core-75b0a2076e14e6a434336ad66b8b7be81f69eddb.tar.gz
eclipse.jdt.core-75b0a2076e14e6a434336ad66b8b7be81f69eddb.tar.xz
eclipse.jdt.core-75b0a2076e14e6a434336ad66b8b7be81f69eddb.zip
Bug 565639 - Compiler generates wrong line number information with textI20200804-1800I20200803-1800I20200803-0210
blocks Change-Id: I68c61486753b8c42baa73c6e23e3ac701648c48b Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java182
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java19
3 files changed, 190 insertions, 13 deletions
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 951ef18760..335bf6ab3a 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
@@ -3111,7 +3111,7 @@ protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOpti
// javac options
javacTestOptions /* javac test options */);
}
- private void runTest(
+ protected void runTest(
// test directory preparation
boolean shouldFlushOutputDirectory,
String[] testFiles,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java
index 99244e58a5..f9400d4522 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TextBlockTest.java
@@ -61,6 +61,42 @@ public class TextBlockTest extends AbstractRegressionTest {
protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions, String[] vmArguments) {
runConformTest(testFiles, expectedOutput, customOptions, vmArguments, new JavacTestOptions("-source 14 --enable-preview"));
}
+ protected void runConformTest(
+ // test directory preparation
+ boolean shouldFlushOutputDirectory,
+ String[] testFiles,
+ //compiler options
+ String[] classLibraries /* class libraries */,
+ Map<String, String> customOptions /* custom options */,
+ // compiler results
+ String expectedCompilerLog,
+ // runtime results
+ String expectedOutputString,
+ String expectedErrorString,
+ String[] vmarguments,
+ // javac options
+ JavacTestOptions javacTestOptions) {
+ runTest(
+ // test directory preparation
+ shouldFlushOutputDirectory /* should flush output directory */,
+ testFiles /* test files */,
+ // compiler options
+ classLibraries /* class libraries */,
+ customOptions /* custom options */,
+ false /* do not perform statements recovery */,
+ null /* no custom requestor */,
+ // compiler results
+ false /* expecting no compiler errors */,
+ expectedCompilerLog /* expected compiler log */,
+ // runtime options
+ false /* do not force execution */,
+ vmarguments /* no vm arguments */,
+ // runtime results
+ expectedOutputString /* expected output string */,
+ expectedErrorString /* expected error string */,
+ // javac options
+ javacTestOptions /* javac test options */);
+ }
public void test001() {
runNegativeTest(
new String[] {
@@ -1352,4 +1388,150 @@ public class TextBlockTest extends AbstractRegressionTest {
getCompilerOptions(),
new String[] {"--enable-preview"});
}
+ public void testBug565639_1() {
+ runConformTest(true,
+ new String[]{
+ "X.java",
+ "public class X {\n" +
+ " static final String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " 5\n" +
+ " \"\"\";\n" +
+ " public static void main(String[] args) {\n" +
+ " throw new RuntimeException(\"This is line 10.\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,
+ getCompilerOptions(),
+ "",
+ "",
+ "Exception in thread \"main\" java.lang.RuntimeException: This is line 10.\n" +
+ " at X.main(X.java:10)",
+ new String[] {"--enable-preview"},
+ new JavacTestOptions("-source 14 --enable-preview"));
+ }
+ public void testBug565639_2() {
+ runConformTest(true,
+ new String[]{
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " 5\n" +
+ " \"\"\";\n" +
+ " throw new RuntimeException(\"This is line 10.\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ null,
+ getCompilerOptions(),
+ "",
+ "",
+ "Exception in thread \"main\" java.lang.RuntimeException: This is line 10.\n" +
+ " at X.main(X.java:10)",
+ new String[] {"--enable-preview"},
+ new JavacTestOptions("-source 14 --enable-preview"));
+ }
+ public void testBug565639_3() {
+ runNegativeTest(new String[]{
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " 5\n" +
+ " \"\"\"\";\n" +
+ " throw new RuntimeException(\"This is line 10.\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " \"\"\"\";\n" +
+ " ^^\n" +
+ "String literal is not properly closed by a double-quote\n" +
+ "----------\n");
+ }
+ public void testBug565639_4() {
+ runNegativeTest(new String[]{
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " 5\n" +
+ " \"\"\"\"\";\n" +
+ " throw new RuntimeException(\"This is line 10.\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " \"\"\"\"\";\n" +
+ " ^^\n" +
+ "Syntax error on token \"\"\"\", delete this token\n" +
+ "----------\n");
+ }
+ public void testBug565639_5() {
+ runNegativeTest(new String[]{
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " 5\n" +
+ " \\\"\"\"\"\"\";\n" +
+ " throw new RuntimeException(\"This is line 10.\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " \\\"\"\"\"\"\";\n" +
+ " ^^\n" +
+ "Syntax error on token \"\"\"\", delete this token\n" +
+ "----------\n");
+ }
+ public void testBug565639_6() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String TEXT_BLOCK = \"\"\"\n" +
+ " 1\n" +
+ " 2\n" +
+ " 3\n" +
+ " 4\n" +
+ " \\\"\"\"\n" +
+ " \"\"\";\n" +
+ " System.out.println(TEXT_BLOCK);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1\n" +
+ "2\n" +
+ "3\n" +
+ "4\n" +
+ "\"\"\"",
+ getCompilerOptions(),
+ new String[] {"--enable-preview"});
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
index 5ec504b558..27abd0b8a5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java
@@ -2050,28 +2050,23 @@ private int scanForStringLiteral() throws InvalidInputException {
if (isTextBlock) {
try {
this.rawStart = this.currentPosition - this.startPosition;
- int terminators = 0;
while (this.currentPosition <= this.eofPosition) {
if (this.currentCharacter == '"') {
lastQuotePos = this.currentPosition;
// look for text block delimiter
if (scanForTextBlockClose()) {
- // Account for just the snippet being passed around
- // If already at the EOF, bail out.
- if (this.currentPosition + 2 < this.source.length && this.source[this.currentPosition + 2] == '"') {
- terminators++;
- if (terminators > 2)
- throw new InvalidInputException(UNTERMINATED_TEXT_BLOCK);
- } else {
- this.currentPosition += 2;
- return TerminalTokens.TokenNameTextBlock;
- }
+ this.currentPosition += 2;
+ return TerminalTokens.TokenNameTextBlock;
}
if (this.withoutUnicodePtr != 0) {
unicodeStore();
}
} else {
- terminators = 0;
+ if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
+ if (this.recordLineSeparator) {
+ pushLineSeparator();
+ }
+ }
}
outer: if (this.currentCharacter == '\\') {
switch(this.source[this.currentPosition]) {

Back to the top