Issue #3700 - Fixing TypeUtil and IncludeExcludeSet to work with null location
+ TypeUtil.getLocationOfClass() respects Class.getClassLoader() of null which means a class belonging to Boot ClassLoader, a Primitive, Void, or a dynamic in-memory class. Using system classloader is incorrect and invalid in Java 9+ + Fixing IncludeExcludeSet.test() to always return TRUE or FALSE never null. Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
cc966dd1f2
commit
5eb3e73400
|
@ -169,7 +169,7 @@ public class IncludeExcludeSet<T,P> implements Predicate<P>
|
|||
/**
|
||||
* Test Included and not Excluded
|
||||
* @param item The item to test
|
||||
* @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded and null if neither
|
||||
* @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded or neither
|
||||
*/
|
||||
public Boolean isIncludedAndNotExcluded(P item)
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ public class IncludeExcludeSet<T,P> implements Predicate<P>
|
|||
if (_includePredicate.test(item))
|
||||
return Boolean.TRUE;
|
||||
|
||||
return null;
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
public boolean hasIncludes()
|
||||
|
|
|
@ -562,10 +562,14 @@ public class TypeUtil
|
|||
|
||||
String resourceName = clazz.getName().replace('.', '/') + ".class";
|
||||
ClassLoader loader = clazz.getClassLoader();
|
||||
URL url = (loader == null ? ClassLoader.getSystemClassLoader() : loader).getResource(resourceName);
|
||||
if (url != null)
|
||||
// null means bootstrap classloader, primitive, void, or dynamic in-memory class
|
||||
if (loader != null)
|
||||
{
|
||||
return URIUtil.getJarSource(url.toURI());
|
||||
URL url = loader.getResource(resourceName);
|
||||
if (url != null)
|
||||
{
|
||||
return URIUtil.getJarSource(url.toURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (URISyntaxException e)
|
||||
|
|
|
@ -18,15 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||
import org.junit.jupiter.api.condition.EnabledOnJre;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -149,6 +145,7 @@ public class TypeUtilTest
|
|||
assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/"));
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
@DisabledOnJre(JRE.JAVA_8)
|
||||
public void testGetLocation_JvmCore_JPMS()
|
||||
|
@ -158,6 +155,15 @@ public class TypeUtilTest
|
|||
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledOnJre(JRE.JAVA_8)
|
||||
public void testGetLocation_JavaLangThreadDeath_JPMS()
|
||||
{
|
||||
// Class from JVM core
|
||||
String expectedJavaBase = "/java.base/";
|
||||
assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnJre(JRE.JAVA_8)
|
||||
public void testGetLocation_JvmCore_Java8RT()
|
||||
|
@ -166,4 +172,14 @@ public class TypeUtilTest
|
|||
String expectedJavaBase = "/rt.jar";
|
||||
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnJre(JRE.JAVA_8)
|
||||
public void testGetLocation_JavaLangThreadDeath_Java8RT()
|
||||
{
|
||||
// Class from JVM core
|
||||
String expectedJavaBase = "/rt.jar";
|
||||
assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue