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(java.base@11.0.16.1/ZipFile.java:1649)
	at java.util.zip.ZipFile.getEntry(java.base@11.0.16.1/ZipFile.java:350)
	- locked <0x00000000ec194810> (a java.util.jar.JarFile)
	at java.util.zip.ZipFile$1.getEntry(java.base@11.0.16.1/ZipFile.java:1143)
	at java.util.jar.JarFile.getEntry0(java.base@11.0.16.1/JarFile.java:586)
	at java.util.jar.JarFile.getEntry(java.base@11.0.16.1/JarFile.java:516)
	at java.util.jar.JarFile.getJarEntry(java.base@11.0.16.1/JarFile.java:478)
	at jdk.internal.loader.URLClassPath$JarLoader.getResource(java.base@11.0.16.1/URLClassPath.java:943)
	at jdk.internal.loader.URLClassPath$JarLoader.findResource(java.base@11.0.16.1/URLClassPath.java:926)
	at jdk.internal.loader.URLClassPath.findResource(java.base@11.0.16.1/URLClassPath.java:292)
	at java.net.URLClassLoader$2.run(java.base@11.0.16.1/URLClassLoader.java:660)
	at java.net.URLClassLoader$2.run(java.base@11.0.16.1/URLClassLoader.java:658)
	at java.security.AccessController.doPrivileged(java.base@11.0.16.1/Native Method)
	at java.net.URLClassLoader.findResource(java.base@11.0.16.1/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(java.base@11.0.16.1/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(java.xml@11.0.16.1/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(java.xml@11.0.16.1/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(java.xml@11.0.16.1/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(java.xml@11.0.16.1/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(java.xml@11.0.16.1/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(java.xml@11.0.16.1/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(java.xml@11.0.16.1/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(java.xml@11.0.16.1/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(java.xml@11.0.16.1/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(java.xml@11.0.16.1/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(java.xml@11.0.16.1/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(java.xml@11.0.16.1/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(java.xml@11.0.16.1/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:374)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(java.xml@11.0.16.1/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(java.xml@11.0.16.1/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(java.xml@11.0.16.1/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(java.xml@11.0.16.1/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(java.xml@11.0.16.1/AbstractSAXParser.java:510)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(java.xml@11.0.16.1/AbstractXMLDocumentParser.java:183)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:2710)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(java.xml@11.0.16.1/XMLDocumentScannerImpl.java:605)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(java.xml@11.0.16.1/XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(java.xml@11.0.16.1/XMLDocumentFragmentScannerImpl.java:534)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:888)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.16.1/XML11Configuration.java:824)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(java.xml@11.0.16.1/XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(java.xml@11.0.16.1/AbstractSAXParser.java:1141)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(java.xml@11.0.16.1/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