Skip to content

Commit

Permalink
Fix NPE in Groovy processing (#8182)
Browse files Browse the repository at this point in the history
* Fix NPE in Groovy processing

* Update AstMessageUtils.groovy
  • Loading branch information
dstepanov authored Oct 19, 2022
1 parent 537148d commit 50ae5bc
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micronaut.ast.groovy.utils

import groovy.transform.CompileStatic
import io.micronaut.core.annotation.Nullable
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.control.Janitor
import org.codehaus.groovy.control.SourceUnit
Expand All @@ -39,8 +40,8 @@ class AstMessageUtils {
* @param node The AST node
* @param message The message
*/
static void warning(final SourceUnit sourceUnit, final ASTNode node, final String message) {
final String sample = sourceUnit.getSample(node.getLineNumber(), node.getColumnNumber(), new Janitor())
static void warning(SourceUnit sourceUnit, @Nullable ASTNode node, String message) {
final String sample = node ? sourceUnit.getSample(node.getLineNumber(), node.getColumnNumber(), new Janitor()) : null
if (sample) {
System.err.println("""WARNING: $message
Expand All @@ -50,7 +51,7 @@ $sample""")
}
}

static void error(SourceUnit sourceUnit, ASTNode expr, String errorMessage) {
static void error(SourceUnit sourceUnit, @Nullable ASTNode expr, String errorMessage) {
if (expr == null) {
error(sourceUnit, errorMessage)
} else {
Expand Down

0 comments on commit 50ae5bc

Please sign in to comment.