Skip to content

Commit 2d4a5a0

Browse files
Groovy: Fix NPE with generics of an unknown class (#7488)
1 parent fd09168 commit 2d4a5a0

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re
133133
StaticTypeCheckingVisitor staticTypeCheckingVisitor = new StaticTypeCheckingVisitor(unit, aClass);
134134
staticTypeCheckingVisitor.setCompilationUnit(compUnit);
135135
staticTypeCheckingVisitor.visitClass(aClass);
136-
} catch (NoClassDefFoundError ignored) {
136+
} catch (NoClassDefFoundError | NullPointerException ignored) {
137+
// Static type checking is best-effort; skip enrichment when Groovy fails internally
138+
// (e.g., NPE in inferDiamondType when diamond is used with an unresolved imported class).
137139
}
138140
}
139141

rewrite-groovy/src/test/java/org/openrewrite/groovy/tree/VariableDeclarationsTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ void diamondOperator() {
111111
);
112112
}
113113

114+
@Test
115+
void diamondOperatorOnUnresolvedImportedType() {
116+
rewriteRun(
117+
groovy(
118+
"""
119+
import a.b.Foo
120+
def x = new Foo<>()
121+
"""
122+
)
123+
);
124+
}
125+
114126
@Test
115127
void singleTypeMultipleVariableDeclaration() {
116128
rewriteRun(

0 commit comments

Comments
 (0)