Skip to content

Commit 2fe1bb2

Browse files
committed
Remove Java 8 workarounds from FeatureClassLoader.
1 parent 63eb558 commit 2fe1bb2

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,6 @@
2424
import java.security.ProtectionDomain;
2525
import java.util.Objects;
2626

27-
import javax.annotation.Nullable;
28-
2927
/**
3028
* This class loader is used to load classes of Spotless features from a search
3129
* path of URLs.<br/>
@@ -113,25 +111,7 @@ private static ByteBuffer urlToByteBuffer(URL url) throws IOException {
113111
return ByteBuffer.wrap(buffer.toByteArray());
114112
}
115113

116-
/**
117-
* Making spotless Java 9+ compatible. In Java 8 (and minor) the bootstrap
118-
* class loader saw every platform class. In Java 9+ it was changed so the
119-
* bootstrap class loader does not see all classes anymore. This might lead
120-
* to ClassNotFoundException in formatters (e.g. freshmark).
121-
*
122-
* @return <code>null</code> on Java 8 (and minor), otherwise <code>PlatformClassLoader</code>
123-
*/
124-
@Nullable
125114
private static ClassLoader getParentClassLoader() {
126-
double version = Double.parseDouble(System.getProperty("java.specification.version"));
127-
if (version > 1.8) {
128-
try {
129-
return (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
130-
} catch (Exception e) {
131-
throw ThrowingEx.asRuntime(e);
132-
}
133-
} else {
134-
return null;
135-
}
115+
return ThrowingEx.get(() -> (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null));
136116
}
137117
}

0 commit comments

Comments
 (0)