8247932: JShell crashes when typing text block

Setting up Log before running javac's scanner, so that errors reported from the scanner are properly ignored.

Reviewed-by: rfield
This commit is contained in:
Jan Lahoda 2020-06-22 12:03:11 +02:00
parent eb758d53f1
commit 61e44cdb6a
2 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ import java.io.InputStream;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,6 +51,9 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import jdk.internal.shellsupport.doc.JavadocFormatter; import jdk.internal.shellsupport.doc.JavadocFormatter;
import jdk.internal.jshell.tool.StopDetectingInputStream.State; import jdk.internal.jshell.tool.StopDetectingInputStream.State;
@ -974,6 +978,15 @@ class ConsoleIOContext extends IOContext {
int pendingBraces = 0; int pendingBraces = 0;
com.sun.tools.javac.util.Context ctx = com.sun.tools.javac.util.Context ctx =
new com.sun.tools.javac.util.Context(); new com.sun.tools.javac.util.Context();
SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("mem://snippet"),
JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return code;
}
};
ctx.put(DiagnosticListener.class, d -> {});
com.sun.tools.javac.util.Log.instance(ctx).useSource(source);
com.sun.tools.javac.parser.ScannerFactory scannerFactory = com.sun.tools.javac.parser.ScannerFactory scannerFactory =
com.sun.tools.javac.parser.ScannerFactory.instance(ctx); com.sun.tools.javac.parser.ScannerFactory.instance(ctx);
com.sun.tools.javac.parser.Scanner scanner = com.sun.tools.javac.parser.Scanner scanner =

View File

@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 8241950 * @bug 8241950 8247932
* @summary Check the UI behavior of indentation * @summary Check the UI behavior of indentation
* @library /tools/lib * @library /tools/lib
* @modules * @modules
@ -70,6 +70,11 @@ public class IndentUITest extends UITesting {
waitOutput(out, "^void test2\\(\\) \\{\n" + waitOutput(out, "^void test2\\(\\) \\{\n" +
CONTINUATION_PROMPT + " System.err.println\\(1\\);\n" + CONTINUATION_PROMPT + " System.err.println\\(1\\);\n" +
CONTINUATION_PROMPT + "\\}"); CONTINUATION_PROMPT + "\\}");
inputSink.write(INTERRUPT);
waitOutput(out, "\u001B\\[\\?2004h" + PROMPT);
inputSink.write("\"\"\"\n");
waitOutput(out, "^\"\"\"\n" +
CONTINUATION_PROMPT);
}); });
} }