changeset 56525:905b2a416250

8223688: JShell: crash on the instantiation of raw anonymous class Reviewed-by: jlahoda
author rfield
date Sat, 01 Jun 2019 14:09:59 -0700
parents e2dbcc6ed36d
children 65896ed82849
files src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java test/langtools/jdk/jshell/ToolBasicTest.java
diffstat 2 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Sat Jun 01 13:41:01 2019 -0700
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Sat Jun 01 14:09:59 2019 -0700
@@ -3499,6 +3499,10 @@
 
         int pstart = (int) diag.getStartPosition();
         int pend = (int) diag.getEndPosition();
+        if (pstart < 0 || pend < 0) {
+            pstart = 0;
+            pend = source.length();
+        }
         Matcher m = LINEBREAK.matcher(source);
         int pstartl = 0;
         int pendl = -2;
@@ -3510,7 +3514,7 @@
                 pstartl = m.end();
             }
         }
-        if (pendl < pstart) {
+        if (pendl < pstartl) {
             pendl = source.length();
         }
         toDisplay.add(source.substring(pstartl, pendl));
--- a/test/langtools/jdk/jshell/ToolBasicTest.java	Sat Jun 01 13:41:01 2019 -0700
+++ b/test/langtools/jdk/jshell/ToolBasicTest.java	Sat Jun 01 14:09:59 2019 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133 8199912 8211694
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133 8199912 8211694 8223688
  * @summary Tests for Basic tests for REPL tool
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
@@ -60,6 +60,7 @@
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.fail;
 
 @Test
@@ -867,4 +868,15 @@
         );
      }
 
+    public void testWarningUnchecked() { //8223688
+        test(false, new String[]{"--no-startup"},
+                a -> assertCommand(a, "abstract class A<T> { A(T t){} }", "|  created class A"),
+                a -> assertCommandCheckOutput(a, "new A(\"\") {}", s -> {
+                            assertStartsWith("|  Warning:");
+                            assertTrue(s.contains("unchecked call"));
+                            assertFalse(s.contains("Exception"));
+                        })
+        );
+    }
+
 }