Skip to content

Commit

Permalink
do not scan classes from java or sun package for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml authored and rspilker committed Aug 20, 2018
1 parent 40570f7 commit 46377b1
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/launch/lombok/launch/ShadowClassLoader.java
Expand Up @@ -296,17 +296,18 @@ private URL getResourceFromLocation(String name, String altName, File location)
return null;
}

private boolean partOfShadow(URL item, String name) {
return inOwnBase(item, name) || isPartOfShadowSuffix(item, name, sclSuffix);
private boolean partOfShadow(String item, String name) {
return !name.startsWith("java/")
&& !name.startsWith("sun/")
&& (inOwnBase(item, name) || isPartOfShadowSuffix(item, name, sclSuffix));
}

/**
* Checks if the stated item is located inside the same classpath root as the jar that hosts ShadowClassLoader.class. {@code item} and {@code name} refer to the same thing.
*/
private boolean inOwnBase(URL item, String name) {
private boolean inOwnBase(String item, String name) {
if (item == null) return false;
String itemString = item.toString();
return (itemString.length() == SELF_BASE_LENGTH + name.length()) && SELF_BASE.regionMatches(0, itemString, 0, SELF_BASE_LENGTH);
return (item.length() == SELF_BASE_LENGTH + name.length()) && SELF_BASE.regionMatches(0, item, 0, SELF_BASE_LENGTH);
}

private static boolean sclFileContainsSuffix(InputStream in, String suffix) throws IOException {
Expand Down Expand Up @@ -386,12 +387,11 @@ private boolean isPartOfShadowSuffixJarBased(String jarLoc, String suffix) {
}
}

private boolean isPartOfShadowSuffix(URL item, String name, String suffix) {
private boolean isPartOfShadowSuffix(String url, String name, String suffix) {
// Instead of throwing an exception or logging, weird, unexpected cases just return false.
// This is better than throwing an exception, because exceptions would make your build tools unusable.
// Such cases are marked with the comment: // *unexpected*
if (item == null) return false;
String url = item.toString();
if (url == null) return false;
if (url.startsWith("file:/")) {
url = urlDecode(url.substring(5));
if (url.length() <= name.length() || !url.endsWith(name) || url.charAt(url.length() - name.length() - 1) != '/') {
Expand Down Expand Up @@ -436,14 +436,14 @@ private boolean isPartOfShadowSuffix(URL item, String name, String suffix) {
Enumeration<URL> sec = super.getResources(name);
while (sec.hasMoreElements()) {
URL item = sec.nextElement();
if (!partOfShadow(item, name)) vector.add(item);
if (!partOfShadow(item.toString(), name)) vector.add(item);
}

if (altName != null) {
Enumeration<URL> tern = super.getResources(altName);
while (tern.hasMoreElements()) {
URL item = tern.nextElement();
if (!partOfShadow(item, altName)) vector.add(item);
if (!partOfShadow(item.toString(), altName)) vector.add(item);
}
}

Expand Down Expand Up @@ -483,11 +483,11 @@ private URL getResource_(String name, boolean noSuper) {

if (altName != null) {
URL res = super.getResource(altName);
if (res != null && (!noSuper || partOfShadow(res, altName))) return res;
if (res != null && (!noSuper || partOfShadow(res.toString(), altName))) return res;
}

URL res = super.getResource(name);
if (res != null && (!noSuper || partOfShadow(res, name))) return res;
if (res != null && (!noSuper || partOfShadow(res.toString(), name))) return res;
return null;
}

Expand All @@ -501,12 +501,12 @@ private boolean exclusionListMatch(String name) {
private URL getResourceSkippingSelf(String name) throws IOException {
URL candidate = super.getResource(name);
if (candidate == null) return null;
if (!partOfShadow(candidate, name)) return candidate;
if (!partOfShadow(candidate.toString(), name)) return candidate;

Enumeration<URL> en = super.getResources(name);
while (en.hasMoreElements()) {
candidate = en.nextElement();
if (!partOfShadow(candidate, name)) return candidate;
if (!partOfShadow(candidate.toString(), name)) return candidate;
}

return null;
Expand Down

0 comments on commit 46377b1

Please sign in to comment.