YARN-9512. [JDK11] TestAuxServices#testCustomizedAuxServiceClassPath fails because of ClassCastException. (#1806)
This commit is contained in:
parent
d7c4f8ab21
commit
14c2c3d69d
|
@ -61,10 +61,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileStatus;
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
|
@ -242,13 +243,20 @@ public class TestAuxServices {
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer getMetaData() {
|
public ByteBuffer getMetaData() {
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
URL[] urls = ((URLClassLoader)loader).getURLs();
|
try {
|
||||||
List<String> urlString = new ArrayList<String>();
|
URL[] urls = ((URLClassLoader) loader).getURLs();
|
||||||
for (URL url : urls) {
|
String joinedString = Arrays.stream(urls)
|
||||||
urlString.add(url.toString());
|
.map(URL::toString)
|
||||||
}
|
.collect(Collectors.joining(","));
|
||||||
String joinedString = StringUtils.join(",", urlString);
|
|
||||||
return ByteBuffer.wrap(joinedString.getBytes());
|
return ByteBuffer.wrap(joinedString.getBytes());
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
// In Java 11+, Thread.currentThread().getContextClassLoader()
|
||||||
|
// returns jdk.internal.loader.ClassLoaders$AppClassLoader
|
||||||
|
// by default and it cannot cast to URLClassLoader.
|
||||||
|
// This exception does not happen when the custom class loader is
|
||||||
|
// used from AuxiliaryServiceWithCustomClassLoader.
|
||||||
|
return super.meta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue