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

Regression in handing CombinedResource WEB-INF between Jetty 11 and Jetty 12 #12739

Closed
Spikhalskiy opened this issue Jan 27, 2025 · 2 comments · Fixed by #12740
Closed

Regression in handing CombinedResource WEB-INF between Jetty 11 and Jetty 12 #12739

Spikhalskiy opened this issue Jan 27, 2025 · 2 comments · Fixed by #12740
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@Spikhalskiy
Copy link

Spikhalskiy commented Jan 27, 2025

Jetty version(s)
Jetty 12.0.16 vs Jetty 11.0.24

Jetty Environment
EE 10

Description

We have embedded jetty servers that use a shared resources "layer" packed as a jar.
The setup works as expected in Jetty 11, but an attempt to migrate to Jetty 12 leads to the following exception:

java.lang.NullPointerException: Cannot invoke "java.net.URI.toString()" because the return value of "org.eclipse.jetty.util.resource.Resource.getURI()" is null
	at org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration.setupXmlConfiguration(JettyWebXmlConfiguration.java:135) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:70) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.webapp.Configurations.configure(Configurations.java:505) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.webapp.WebAppContext.configure(WebAppContext.java:484) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.webapp.WebAppContext.startContext(WebAppContext.java:1300) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.servlet.ServletContextHandler.lambda$doStart$0(ServletContextHandler.java:1047) ~[jetty-ee10-servlet-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.server.handler.ContextHandler$ScopedContext.call(ContextHandler.java:1452) ~[jetty-server-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.servlet.ServletContextHandler.doStart(ServletContextHandler.java:1044) ~[jetty-ee10-servlet-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.ee10.webapp.WebAppContext.doStart(WebAppContext.java:503) ~[jetty-ee10-webapp-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:120) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.server.Handler$Abstract.doStart(Handler.java:491) ~[jetty-server-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.server.Server.start(Server.java:641) ~[jetty-server-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:120) ~[jetty-util-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.server.Handler$Abstract.doStart(Handler.java:491) ~[jetty-server-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.server.Server.doStart(Server.java:582) ~[jetty-server-12.0.16.jar:12.0.16]
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93) ~[jetty-util-12.0.16.jar:12.0.16]

Looking further into Jetty codebase the exception happens in JettyWebXmlConfiguration:

        props.put(PROPERTY_WEB_INF_URI, XmlConfiguration.normalizeURI(webInf.getURI().toString()));

because webInf is a CombinedResource and getURI returns null for it. Meanwhile, it looks like it's allowed and expected for webInf resource to be a CombinedResource based on the following comment from WebAppContext:

    public Resource getWebInf() throws IOException
    {
        if (getBaseResource() == null)
            return null;

        // Is there a WEB-INF directory anywhere in the Resource Base?
        // ResourceBase could be a CombinedResource
        // The result could be a CombinedResource with multiple WEB-INF directories
        // Can return from WEB-INF/lib/foo.jar!/WEB-INF
        // Can also never return from a META-INF/versions/#/WEB-INF location
        Resource webInf = getBaseResource().resolve("WEB-INF/");
        if (Resources.isReadableDirectory(webInf))
            return webInf;

        return null;
    }

This looks like a regression in a supported scenario from Jetty 11.

Image

@Spikhalskiy Spikhalskiy added the Bug For general bugs on Jetty side label Jan 27, 2025
@janbartel janbartel self-assigned this Jan 27, 2025
@janbartel
Copy link
Contributor

@Spikhalskiy are you relying on the value of the properties that are set in JettyWebXmlConfiguration? If those properties were skipped if WEB-INF was a CombinedResource would that be a problem for you?

@Spikhalskiy
Copy link
Author

Spikhalskiy commented Jan 27, 2025

@janbartel I'm not sure I understand what scope of properties you mean, but the answer is likely yes, we are relying on them. We need at least "contextPath" from jetty-web.xml to get the correct bindings.

janbartel added a commit that referenced this issue Jan 29, 2025
* Issue #12739 Fix NPE if WEB-INF is CombinedResource

* Update with debug log if WEB-INF uri is null
sbordet pushed a commit that referenced this issue Feb 9, 2025
* Issue #12739 Fix NPE if WEB-INF is CombinedResource

* Update with debug log if WEB-INF uri is null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants