IllegalArgumentException in highlights
Sven Reimers
sven.reimers at gmail.com
Fri Jun 13 21:41:23 UTC 2025
Hi,
thanks for the reproducer.
With
https://download.java.net/java/early_access/jdk26/docs/api/jdk.jshell/jdk/jshell/SourceCodeAnalysis.html#highlights(java.lang.String)
I would expect an empty list, if anything goes wrong, not an exception..
wdyt?
Sven
Archie Cobbs <archie.cobbs at gmail.com> schrieb am Fr., 13. Juni 2025, 18:57:
> Here's a reproducer using JDK 25-ea:
>
> $ jshell
> | Welcome to JShell -- Version 25-ea
> | For an introduction type: /help intro
>
> jshell> import jdk.jshell.*
>
> jshell> JShell jsh = JShell.builder().out(System.out).build();
> jsh ==> jdk.jshell.JShell at 1134affc
>
> jshell> var sca = jsh.sourceCodeAnalysis()
> sca ==> jdk.jshell.SourceCodeAnalysisImpl at 73f792cf
>
> jshell> sca.highlights("System.out.println(\"");
> | Exception java.lang.IllegalArgumentException
> | at JCDiagnostic.<init> (JCDiagnostic.java:659)
> | at JCDiagnostic.<init> (JCDiagnostic.java:641)
> | at JCDiagnostic$Factory.create (JCDiagnostic.java:294)
> | at JCDiagnostic$Factory.error (JCDiagnostic.java:111)
> | at AbstractLog.error (AbstractLog.java:144)
> | at JavaTokenizer.lexError (JavaTokenizer.java:201)
> | at JavaTokenizer.scanString (JavaTokenizer.java:470)
> | at JavaTokenizer.readToken (JavaTokenizer.java:1017)
> | at Scanner.nextToken (Scanner.java:124)
> | at SourceCodeAnalysisImpl.lambda$highlights$0
> (SourceCodeAnalysisImpl.java:680)
> | at TaskFactory.lambda$runTask$1 (TaskFactory.java:218)
> | at JavacTaskPool.getTask (JavacTaskPool.java:193)
> | at TaskFactory.runTask (TaskFactory.java:211)
> | at TaskFactory.analyze (TaskFactory.java:180)
> | at TaskFactory.analyze (TaskFactory.java:166)
> | at TaskFactory.analyze (TaskFactory.java:155)
> | at SourceCodeAnalysisImpl.highlights
> (SourceCodeAnalysisImpl.java:651)
> | at (#4:1)
>
> Here's what happens:
>
> - JShell is doing some parsing without establishing the current source
> file via Log.useSource() (I've seen this in other JShell scenarios as
> well)
> - The JCDiagnostic() constructor has an assertion that if a diagnostic
> has a source code position then it also must have a current source file.
>
> So the first question would be: who is right?
>
> -Archie
>
> On Fri, Jun 13, 2025 at 2:21 AM Volkan Yazıcı <volkan at yazi.ci> wrote:
>
>> Downloaded JDK 24.0.1
>> <https://www.oracle.com/java/technologies/downloads/#java24>, yet could
>> not reproduce the issue:
>>
>> $ jdk-24.0.1/bin/jshell
>> | Welcome to JShell -- Version 24.0.1
>> | For an introduction type: /help intro
>>
>> jshell> System.out.println("
>> | Error:
>> | unclosed string literal
>> | System.out.println("
>> |
>>
>> Would you mind sharing more details to reproduce the issue, please? Which
>> JDK distribution do you use? Which major/minor/patch version? Which
>> architecture & OS?
>>
>> On Thu, Jun 12, 2025 at 9:19 PM Sven Reimers <sven.reimers at gmail.com>
>> wrote:
>>
>>> JDK 24
>>>
>>> Sven
>>>
>>> On Thu, Jun 12, 2025 at 8:56 PM Archie Cobbs <archie.cobbs at gmail.com>
>>> wrote:
>>>
>>>> What JDK version?
>>>>
>>>> On Thu, Jun 12, 2025 at 1:39 PM Sven Reimers <sven.reimers at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> working on highlighting in JTaccuino I found
>>>>>
>>>>> Caused by: java.lang.IllegalArgumentException
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.util.JCDiagnostic.<init>(JCDiagnostic.java:647)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.util.JCDiagnostic.<init>(JCDiagnostic.java:627)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.util.JCDiagnostic$Factory.create(JCDiagnostic.java:301)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.util.JCDiagnostic$Factory.error(JCDiagnostic.java:114)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.util.AbstractLog.error(AbstractLog.java:145)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.lexError(JavaTokenizer.java:202)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.scanString(JavaTokenizer.java:468)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:1015)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java:124)
>>>>> at
>>>>> jdk.jshell/jdk.jshell.SourceCodeAnalysisImpl.lambda$highlights$0(SourceCodeAnalysisImpl.java:647)
>>>>> at
>>>>> jdk.jshell/jdk.jshell.TaskFactory.lambda$runTask$1(TaskFactory.java:218)
>>>>> at
>>>>> jdk.compiler/com.sun.tools.javac.api.JavacTaskPool.getTask(JavacTaskPool.java:193)
>>>>> at jdk.jshell/jdk.jshell.TaskFactory.runTask(TaskFactory.java:211)
>>>>> at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:180)
>>>>> at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:166)
>>>>> at jdk.jshell/jdk.jshell.TaskFactory.analyze(TaskFactory.java:155)
>>>>> at
>>>>> jdk.jshell/jdk.jshell.SourceCodeAnalysisImpl.highlights(SourceCodeAnalysisImpl.java:618)
>>>>>
>>>>> happening, when a snippet is sent with a not closed quoted string, e.g.
>>>>>
>>>>> System.out.println("
>>>>>
>>>>> I assume this should not happen?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Sven
>>>>>
>>>>> --
>>>>> Sven Reimers
>>>>>
>>>>> * Java Champion
>>>>> * Apache NetBeans PMC: http://netbeans.apache.org
>>>>> * JUG Leader JUG Bodensee: https://www.meetup.com/JUG-Bodensee
>>>>>
>>>>
>>>>
>>>> --
>>>> Archie L. Cobbs
>>>>
>>>
>>>
>>> --
>>> Sven Reimers
>>>
>>> * Java Champion
>>> * Apache NetBeans PMC: http://netbeans.apache.org
>>> * JUG Leader JUG Bodensee: https://www.meetup.com/JUG-Bodensee
>>> * Duke's Choice Award Winner 2009 & 2018
>>>
>>> * LinkedIn: http://www.linkedin.com/in/svenreimers
>>>
>>
>
> --
> Archie L. Cobbs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/kulla-dev/attachments/20250613/0cc237d9/attachment-0001.htm>
More information about the kulla-dev
mailing list