Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of commons-discovery #414

Open
jglick opened this issue Nov 3, 2022 · 0 comments
Open

Remove use of commons-discovery #414

jglick opened this issue Nov 3, 2022 · 0 comments

Comments

@jglick
Copy link
Member

jglick commented Nov 3, 2022

I was browsing the thread dump of a controller slow to start up and was surprised to see a mention of JDK 1.2 and a library I had not heard of.

Thread stack
"Handling GET /…/user/admin/contextMenu from … : Jetty (winstone)-…" … elapsed=3.93s … runnable  […]
   java.lang.Thread.State: RUNNABLE
	at java.util.zip.ZipFile$Source.getEntryPos([email protected]/ZipFile.java:1649)
	at java.util.zip.ZipFile.getEntry([email protected]/ZipFile.java:350)
	- locked <0x00000000ec194810> (a java.util.jar.JarFile)
	at java.util.zip.ZipFile$1.getEntry([email protected]/ZipFile.java:1143)
	at java.util.jar.JarFile.getEntry0([email protected]/JarFile.java:586)
	at java.util.jar.JarFile.getEntry([email protected]/JarFile.java:516)
	at java.util.jar.JarFile.getJarEntry([email protected]/JarFile.java:478)
	at jdk.internal.loader.URLClassPath$JarLoader.getResource([email protected]/URLClassPath.java:943)
	at jdk.internal.loader.URLClassPath$JarLoader.findResource([email protected]/URLClassPath.java:926)
	at jdk.internal.loader.URLClassPath.findResource([email protected]/URLClassPath.java:292)
	at java.net.URLClassLoader$2.run([email protected]/URLClassLoader.java:660)
	at java.net.URLClassLoader$2.run([email protected]/URLClassLoader.java:658)
	at java.security.AccessController.doPrivileged([email protected]/Native Method)
	at java.net.URLClassLoader.findResource([email protected]/URLClassLoader.java:657)
	at org.eclipse.jetty.webapp.WebAppClassLoader.getResource(WebAppClassLoader.java:408)
	at org.apache.commons.discovery.jdk.JDK12Hooks.getResources(JDK12Hooks.java:134)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResources(DiscoverResources.java:124)
	at org.apache.commons.discovery.resource.DiscoverResources$1.getNextResource(DiscoverResources.java:98)
	at org.apache.commons.discovery.resource.DiscoverResources$1.hasNext(DiscoverResources.java:84)
	at org.apache.commons.discovery.resource.names.DiscoverNamesInFile$1.getNextClassNames(DiscoverNamesInFile.java:226)
	at org.apache.commons.discovery.resource.names.DiscoverNamesInFile$1.getNextClassName(DiscoverNamesInFile.java:209)
	at org.apache.commons.discovery.resource.names.DiscoverNamesInFile$1.hasNext(DiscoverNamesInFile.java:196)
	at org.kohsuke.stapler.Facet.discoverExtensions(Facet.java:93)
	at org.kohsuke.stapler.jelly.JellyTagFileLoader.discover(JellyTagFileLoader.java:50)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.<init>(CustomTagLibrary.java:73)
	at org.kohsuke.stapler.jelly.JellyClassLoaderTearOff.lambda$getTagLibrary$0(JellyClassLoaderTearOff.java:76)
	at org.kohsuke.stapler.jelly.JellyClassLoaderTearOff$$Lambda$241/0x00000008402fe040.apply(Unknown Source)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent([email protected]/ConcurrentHashMap.java:1705)
	- locked <0x00000000e8400ae8> (a java.util.concurrent.ConcurrentHashMap$ReservationNode)
	at org.kohsuke.stapler.jelly.JellyClassLoaderTearOff.getTagLibrary(JellyClassLoaderTearOff.java:65)
	at org.kohsuke.stapler.jelly.CustomJellyContext.getTagLibrary(CustomJellyContext.java:112)
	at org.apache.commons.jelly.JellyContext.getTagLibrary(JellyContext.java:457)
	at org.kohsuke.stapler.jelly.CustomJellyContext.getTagLibrary(CustomJellyContext.java:108)
	at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1066)
	at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement([email protected]/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement([email protected]/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement([email protected]/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next([email protected]/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next([email protected]/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next([email protected]/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument([email protected]/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse([email protected]/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse([email protected]/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse([email protected]/SAXParserImpl.java:647)
	at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
	at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScript(CustomTagLibrary.java:152)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:132)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:121)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.createTagScript(CustomTagLibrary.java:78)
	at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1091)
	at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement([email protected]/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement([email protected]/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement([email protected]/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next([email protected]/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next([email protected]/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next([email protected]/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument([email protected]/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse([email protected]/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse([email protected]/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse([email protected]/SAXParserImpl.java:647)
	at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
	at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScript(CustomTagLibrary.java:152)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:132)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:121)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.createTagScript(CustomTagLibrary.java:78)
	at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1091)
	at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement([email protected]/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement([email protected]/XMLNSDocumentScannerImpl.java:374)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next([email protected]/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next([email protected]/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next([email protected]/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument([email protected]/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse([email protected]/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse([email protected]/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse([email protected]/SAXParserImpl.java:647)
	at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
	at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScript(CustomTagLibrary.java:152)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:132)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:121)
	at org.kohsuke.stapler.jelly.CustomTagLibrary.createTagScript(CustomTagLibrary.java:78)
	at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1091)
	at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement([email protected]/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement([email protected]/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement([email protected]/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next([email protected]/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next([email protected]/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next([email protected]/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument([email protected]/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse([email protected]/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse([email protected]/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse([email protected]/SAXParserImpl.java:647)
	at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
	at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
	at org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript(JellyClassTearOff.java:57)
	at org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript(JellyClassTearOff.java:47)
	at org.kohsuke.stapler.AbstractTearOff.resolveScript(AbstractTearOff.java:166)
	at org.kohsuke.stapler.jelly.JellyClassTearOff.resolveScript(JellyClassTearOff.java:95)
	at org.kohsuke.stapler.jelly.JellyClassTearOff.resolveScript(JellyClassTearOff.java:47)
	at org.kohsuke.stapler.AbstractTearOff.loadScript(AbstractTearOff.java:197)
	at org.kohsuke.stapler.CachingScriptLoader.findScript(CachingScriptLoader.java:61)
	at jenkins.model.ModelObjectWithContextMenu$ContextMenu.from(ModelObjectWithContextMenu.java:242)
	at jenkins.model.ModelObjectWithContextMenu$ContextMenu.from(ModelObjectWithContextMenu.java:237)
	at hudson.model.User.doContextMenu(User.java:1037)

It looks like

/**
* Discovers all the facets in the classloader.
*/
public static List<Facet> discover(ClassLoader cl) {
return discoverExtensions(Facet.class, cl);
}
public static <T> List<T> discoverExtensions(Class<T> type, ClassLoader... cls) {
List<T> r = new ArrayList<>();
Set<String> classNames = new HashSet<>();
for (ClassLoader cl : cls) {
ClassLoaders classLoaders = new ClassLoaders();
classLoaders.put(cl);
DiscoverServiceNames dc = new DiscoverServiceNames(classLoaders);
ResourceNameIterator itr = dc.findResourceNames(type.getName());
while(itr.hasNext()) {
String name = itr.nextResourceName();
if (!classNames.add(name)) continue; // avoid duplication
Class<? extends T> c;
try {
c = cl.loadClass(name).asSubclass(type);
} catch (ClassNotFoundException e) {
LOGGER.log(Level.WARNING, "Failed to load "+name,e);
continue;
}
try {
r.add(c.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
LOGGER.log(Level.WARNING, "Failed to instantiate "+c,e);
}
}
}
return r;
}
could be replaced with a couple of lines using the standard ServiceLoader. (The only implementations are JellyFacet and GroovyFacet.)

Actually removing the library dep will be a bit trickier. Jenkins core implicitly uses it via Stapler https://github.com/jenkinsci/jenkins/blob/6d179998e18adfbaa4e443c7e837135bf36c53d7/core/src/main/java/hudson/cli/CLICommand.java#L564-L582 though it looks like this duplicates what is also done via SezPoz https://github.com/jenkinsci/jenkins/blob/6d179998e18adfbaa4e443c7e837135bf36c53d7/core/src/main/java/hudson/cli/CLICommand.java#L516-L528 and see https://github.com/jenkinsci/jenkins/blob/632033d6ada7c04bbc77ae710dc0a4635fdf9baa/core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java#L38 as well. Jelly also uses the lib for reasons I do not yet follow: https://github.com/jenkinsci/jelly/blob/114461d92a3c38d2b2e8f3b500a757a59b4035b0/src/java/org/apache/commons/jelly/impl/DefaultTagLibraryResolver.java#L67-L113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant