[ 
https://issues.apache.org/jira/browse/GROOVY-10760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17607276#comment-17607276
 ] 

Christopher Smith commented on GROOVY-10760:
--------------------------------------------

Oddly enough, this code _in and of itself_ seems to be working fine; if there 
are no other messages on the errorCollector, I get the warning printed as 
expected. It's only when I have an additional compile-time error that the 
entire process throws an NPE here.

> NPE in LocatedMessage suppresses errorCollector output
> ------------------------------------------------------
>
>                 Key: GROOVY-10760
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10760
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.5
>            Reporter: Christopher Smith
>            Priority: Major
>
> In an AST transformation, I'm using this check to avoid duplicating a class 
> definition:
> {code}
> if (source.AST.unit.getClass(fqcn)) {
>   source.errorCollector.addWarning(LIKELY_ERRORS, "class $fqcn already 
> exists", source.CST, source)
>   return
> }
> {code}
> This can (sometimes?) trigger an exception in groovyc:
> {code}
> [ERROR] Error executing Maven.
> java.lang.NullPointerException
>     at org.codehaus.groovy.control.messages.LocatedMessage.write 
> (LocatedMessage.java:55)
>     at org.codehaus.groovy.control.messages.WarningMessage.write 
> (WarningMessage.java:87)
>     at org.codehaus.groovy.control.ErrorCollector.write 
> (ErrorCollector.java:303)
>     at org.codehaus.groovy.control.ErrorCollector.write 
> (ErrorCollector.java:322)
>     at 
> org.codehaus.groovy.control.MultipleCompilationErrorsException.getMessage 
> (MultipleCompilationErrorsException.java:60)
>     at org.apache.maven.exception.DefaultExceptionHandler.getMessage 
> (DefaultExceptionHandler.java:277)
>     at org.apache.maven.exception.DefaultExceptionHandler.handle 
> (DefaultExceptionHandler.java:124)
>     at org.apache.maven.exception.DefaultExceptionHandler.handleException 
> (DefaultExceptionHandler.java:96)
>     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
>     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
>     at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:566)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced 
> (Launcher.java:282)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launch 
> (Launcher.java:225)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode 
> (Launcher.java:406)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.main 
> (Launcher.java:347)
> {code}
> This seems to happen only when there are multiple messages to be printed; the 
> message printed by this line prints successfully in the case of a single 
> message. (The only other use of the error collector is a plain call to 
> {{errorCollector.addException(ex, source)}}.)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to