|
61 | 61 | import java.util.Arrays; |
62 | 62 | import java.util.Collection; |
63 | 63 | import java.util.HashSet; |
64 | | -import java.util.List; |
65 | 64 | import java.util.Map; |
66 | 65 | import java.util.Map.Entry; |
67 | 66 | import java.util.Set; |
| 67 | +import java.util.stream.Collectors; |
| 68 | + |
68 | 69 | import org.apache.hadoop.conf.Configuration; |
69 | 70 | import org.apache.hadoop.fs.FileStatus; |
70 | 71 | import org.apache.hadoop.fs.FileSystem; |
@@ -242,13 +243,20 @@ public ServiceC() { |
242 | 243 | @Override |
243 | 244 | public ByteBuffer getMetaData() { |
244 | 245 | ClassLoader loader = Thread.currentThread().getContextClassLoader(); |
245 | | - URL[] urls = ((URLClassLoader)loader).getURLs(); |
246 | | - List<String> urlString = new ArrayList<String>(); |
247 | | - for (URL url : urls) { |
248 | | - urlString.add(url.toString()); |
| 246 | + try { |
| 247 | + URL[] urls = ((URLClassLoader) loader).getURLs(); |
| 248 | + String joinedString = Arrays.stream(urls) |
| 249 | + .map(URL::toString) |
| 250 | + .collect(Collectors.joining(",")); |
| 251 | + return ByteBuffer.wrap(joinedString.getBytes()); |
| 252 | + } catch (ClassCastException e) { |
| 253 | + // In Java 11+, Thread.currentThread().getContextClassLoader() |
| 254 | + // returns jdk.internal.loader.ClassLoaders$AppClassLoader |
| 255 | + // by default and it cannot cast to URLClassLoader. |
| 256 | + // This exception does not happen when the custom class loader is |
| 257 | + // used from AuxiliaryServiceWithCustomClassLoader. |
| 258 | + return super.meta; |
249 | 259 | } |
250 | | - String joinedString = StringUtils.join(",", urlString); |
251 | | - return ByteBuffer.wrap(joinedString.getBytes()); |
252 | 260 | } |
253 | 261 | } |
254 | 262 |
|
|
0 commit comments