Skip to content

Conversation

@RefuX
Copy link
Contributor

@RefuX RefuX commented May 28, 2025

This is a rather specific workflow, where if you are loading an artifact (via the MavenRepository), and the artifact is a version of RELEASE, LATEST or -SNAPSHOT (logic in DefaultVersionResolver.resolveVersion) and contains maven-metadata.xml, then during resolution in org.apache.maven.repository.internal.DefaultVersionResolver.readVersions it will instantiate a MetadataStaxReader and then read.

The first thing read does is:
XMLInputFactory factory = XMLInputFactory.newFactory();

However due to the use of the maven.shading plugin with minimize = true the shaded output classes don't include the WstxInputFactory.

Even though in META-INF/services/javax.xml.stream.XMLInputFactory is:
org.eclipse.osgi.technology.shaded.wstx.stax.WstxInputFactory

I played around with the maven.shading plugin quite a bit, but I couldn't figure out how to configure it to not minimise the WstxInputFactory. So the result is my heavy-handed solution to just hard-code a reference 🤦‍♂️

Just for reference the is my stacktrace i was dealing with:

Caused by: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider org.eclipse.osgi.technology.shaded.wstx.stax.WstxInputFactory not found
    at java.util.ServiceLoader.fail (ServiceLoader.java:593)
    at java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass (ServiceLoader.java:1219)
    at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService (ServiceLoader.java:1228)
    at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext (ServiceLoader.java:1273)
    at java.util.ServiceLoader$2.hasNext (ServiceLoader.java:1309)
    at java.util.ServiceLoader$3.hasNext (ServiceLoader.java:1393)
    at javax.xml.stream.FactoryFinder$1.run (FactoryFinder.java:304)
    at java.security.AccessController.doPrivileged (AccessController.java:319)
    at javax.xml.stream.FactoryFinder.findServiceProvider (FactoryFinder.java:293)
    at javax.xml.stream.FactoryFinder.find (FactoryFinder.java:264)
    at javax.xml.stream.FactoryFinder.find (FactoryFinder.java:210)
    at javax.xml.stream.XMLInputFactory.newFactory (XMLInputFactory.java:185)
    at org.eclipse.osgi.technology.shaded.maven.metadata.v4.MetadataStaxReader.read (MetadataStaxReader.java:367)
    at org.eclipse.osgi.technology.shaded.maven.repository.internal.DefaultVersionResolver.readVersions (DefaultVersionResolver.java:249)
    at org.eclipse.osgi.technology.shaded.maven.repository.internal.DefaultVersionResolver.resolveVersion (DefaultVersionResolver.java:178)
    at org.eclipse.osgi.technology.shaded.aether.internal.impl.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:278)
    at org.eclipse.osgi.technology.shaded.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts (DefaultArtifactResolver.java:201)
    at org.eclipse.osgi.technology.shaded.aether.internal.impl.DefaultArtifactResolver.resolveArtifact (DefaultArtifactResolver.java:180)
    at org.eclipse.osgi.technology.shaded.aether.internal.impl.DefaultRepositorySystem.resolveArtifact (DefaultRepositorySystem.java:213)
    at org.eclipse.osgi.technology.featurelauncher.repository.maven.AbstractMavenRepositoryImpl.getArtifactPath (AbstractMavenRepositoryImpl.java:124)
    at org.eclipse.osgi.technology.featurelauncher.repository.maven.AbstractMavenRepositoryImpl.getArtifactData (AbstractMavenRepositoryImpl.java:89)
    at org.eclipse.osgi.technology.featurelauncher.repository.common.osgi.ArtifactRepositoryAdapter.getArtifact (ArtifactRepositoryAdapter.java:32)
    at org.eclipse.osgi.technology.featurelauncher.launch.secondstage.SecondStageLauncherImpl.getArtifact (SecondStageLauncherImpl.java:373)
    at org.eclipse.osgi.technology.featurelauncher.launch.secondstage.SecondStageLauncherImpl.installBundle (SecondStageLauncherImpl.java:347)
    at org.eclipse.osgi.technology.featurelauncher.launch.secondstage.SecondStageLauncherImpl.installBundle (SecondStageLauncherImpl.java:336)
    at org.eclipse.osgi.technology.featurelauncher.launch.secondstage.SecondStageLauncherImpl.installBundles (SecondStageLauncherImpl.java:324)
    at org.eclipse.osgi.technology.featurelauncher.launch.secondstage.SecondStageLauncherImpl.launchFramework (SecondStageLauncherImpl.java:108)
    at org.eclipse.osgi.technology.featurelauncher.launch.launcher.FeatureLauncherImpl$LaunchBuilderImpl.launchFramework (FeatureLauncherImpl.java:286)
    at com.kentyou.ocx2024.featurelauncher.demo2.API_Launcher.main (API_Launcher.java:48)
    at org.codehaus.mojo.exec.ExecJavaMojo.doMain (ExecJavaMojo.java:375)
    at org.codehaus.mojo.exec.ExecJavaMojo.doExec (ExecJavaMojo.java:364)
    at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0 (ExecJavaMojo.java:286)
    at java.lang.Thread.run (Thread.java:1583)

…ng WstxInputFactory and WstxEventFactory to be minimised, even though they are referenced in META-INF/services
@timothyjward
Copy link
Contributor

Thank you for the detailed bug report. I think that it's likely that we need to configure the entry points for the shade plugin so that it doesn't drop the things that we need. This will probably need to include several of these types of service dependencies.

Are you able to provide an example of an artifact for which this failure occurs? It would be useful to get a failing test case together so that we can successfully test a fix.

@RefuX
Copy link
Contributor Author

RefuX commented May 29, 2025

For a simple test case if you clone https://github.com/RefuX/OCX2024-feature-launcher-demo.git and checkout the getworking branch. Then run the demo-2 exec:java goal you should get the error.

The error occurs when the Feature Launcher tries to install the
org.eclipse.osgi-technology.featurelauncher.repository:common.osgi:1.0.0-SNAPSHOT bundle.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Successfully merging this pull request may close these issues.

2 participants