Skip to content

Commit

Permalink
More safeguards against failing Lombok initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 5, 2024
1 parent 6f22790 commit 3e068e6
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -136,7 +136,6 @@ private ReloadableJava17Parser(
}
}
if (!found) {
annotationProcessors = emptyList();
break LOMBOK;
}
System.setProperty("shadow.override.lombok", String.join(File.pathSeparator, overrideClasspath));
Expand All @@ -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();
Expand Down

0 comments on commit 3e068e6

Please sign in to comment.