From 3e068e6a127b3827e5ab7bc0f453f47793c780a7 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Tue, 5 Nov 2024 12:13:52 +0100 Subject: [PATCH] More safeguards against failing Lombok initialization --- .../java/isolated/ReloadableJava17Parser.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java index e1a75d36415..c7d9bf60a13 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java @@ -53,7 +53,6 @@ import javax.tools.StandardLocation; import java.io.*; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.nio.charset.Charset; import java.nio.file.Path; @@ -117,6 +116,7 @@ private ReloadableJava17Parser( LOMBOK: if (classpath != null && classpath.stream().anyMatch(it -> it.toString().contains("lombok"))) { + Processor lombokProcessor = null; try { // https://projectlombok.org/contributing/lombok-execution-path String systemClasspath = System.getProperty("java.class.path"); @@ -136,7 +136,6 @@ private ReloadableJava17Parser( } } if (!found) { - annotationProcessors = emptyList(); break LOMBOK; } System.setProperty("shadow.override.lombok", String.join(File.pathSeparator, overrideClasspath)); @@ -158,12 +157,12 @@ private ReloadableJava17Parser( emptyList(), singletonList("lombok.patcher.Symbols") ); - Processor lombokProcessor = (Processor) lombokShadowLoader.loadClass("lombok.core.AnnotationProcessor").getDeclaredConstructor().newInstance(); - annotationProcessors = singletonList(lombokProcessor); + lombokProcessor = (Processor) lombokShadowLoader.loadClass("lombok.core.AnnotationProcessor").getDeclaredConstructor().newInstance(); Options.instance(context).put(Option.PROCESSOR, "lombok.launch.AnnotationProcessorHider$AnnotationProcessor"); - } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | - InvocationTargetException e) { - throw new RuntimeException(e); + } catch (ReflectiveOperationException ignore) { + // Lombok was not found or could not be initialized + } finally { + annotationProcessors = lombokProcessor != null ? singletonList(lombokProcessor) : emptyList(); } } else { annotationProcessors = emptyList();