From 4c46f99dfbd2c9e7d9ccc76a8f3a1c07c87933c9 Mon Sep 17 00:00:00 2001 From: Anders Sundelin Date: Tue, 26 Nov 2019 10:58:19 +0100 Subject: [PATCH] Fix NPE in EclipseXmlFormatterStepImpl (#489) The method EclipseXmlFormatterStepImpl used the return value of SpotlessEclipseFramework.setup() ir order to take decisions whether or not to initialize. This introduced a race condition, which is fixed by making the method synchronized. Also removed another empty if-statement in GrEclipseFormatterStepImpl which also called SpotlessEclipseFramework.setup() --- .../extra/eclipse/groovy/GrEclipseFormatterStepImpl.java | 4 ++-- .../extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java b/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java index 1bea0171b7..a7af527bc5 100644 --- a/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java +++ b/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java @@ -55,14 +55,14 @@ public class GrEclipseFormatterStepImpl { private final boolean ignoreFormatterProblems; public GrEclipseFormatterStepImpl(final Properties properties) throws Exception { - if (SpotlessEclipseFramework.setup( + SpotlessEclipseFramework.setup( config -> { config.applyDefault(); config.useSlf4J(GrEclipseFormatterStepImpl.class.getPackage().getName()); }, plugins -> { plugins.add(new GroovyCoreActivator()); - })) {} + }); PreferenceStore preferences = createPreferences(properties); preferencesStore = new FormatterPreferencesOnStore(preferences); ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false")); diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java index 7be4728a45..3fb3e5158e 100644 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java @@ -67,7 +67,7 @@ public EclipseXmlFormatterStepImpl(Properties properties) throws Exception { xmlAdapterFactory = new ModelQueryAdapterFactoryForXML(); } - private static void setupFramework(boolean resolveExternalURI) throws BundleException { + private synchronized static void setupFramework(boolean resolveExternalURI) throws BundleException { if (SpotlessEclipseFramework.setup( config -> { config.applyDefault();