Skip to content

Commit 00db051

Browse files
committed
fix(java): handle null newTestMethod in JavaCodeModifier #312
Add null check for newTestMethod and log error with context.
1 parent d4ad7fd commit 00db051

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

java/src/main/kotlin/cc/unitmesh/idea/context/JavaCodeModifier.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ open class JavaCodeModifier : CodeModifier {
140140
try {
141141
rootElement.add(newTestMethod)
142142
} catch (e: Throwable) {
143+
if (newTestMethod == null) {
144+
log.error("Failed to create method from text: $code")
145+
return@runWriteCommandAction
146+
}
147+
143148
val classEndOffset = rootElement.textRange.endOffset
144149
val document = PsiDocumentManager.getInstance(project).getDocument(rootElement.containingFile)
145150
document?.insertString(classEndOffset - 1, "\n ")

0 commit comments

Comments
 (0)