-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty 12 - Issue #8474 - return null on resolve() if resource doesn't exist #8597
Jetty 12 - Issue #8474 - return null on resolve() if resource doesn't exist #8597
Conversation
@sbordet here's the minimal change to have PathResource.resolve() behave the same as ResourceCollection.resolve(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of an omnibus PR. There are too many changes in it that are unrelated to the premise (of a null return).
There is goodness in this PR, but it is too hard to review when there are 70 files changed with renames, reformatting, various fixes and cleanups.
Can you break this out into multiple PRs, so that ultimately there is a single PR with the null return change.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
Outdated
Show resolved
Hide resolved
b277dac
to
7f86ec1
Compare
Thank you for the preliminary review. For now, hold off on any further reviews until I can move some of the oddball changes out of this PR into separate PRs (as once those are merged, it will cause a rebase in this PR to clean out those changes) |
The removal of |
For anything like renaming of variables / fields etc. I think you can probably do them without a PR if they are not part of the public API. Just check with another developer and if they are OK, push directly to the branch. |
…experiment-resource-resolve-null-on-notexist
…experiment-resource-resolve-null-on-notexist
…jar:file: based URI)
…experiment-resource-resolve-null-on-notexist
…-existent Resource
@@ -252,30 +259,25 @@ public static Stream<Arguments> scenarios() throws Exception | |||
|
|||
public WorkDir workDir; | |||
|
|||
@Disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to revisit this
jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java
Fixed
Show fixed
Hide fixed
jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/ClassMatcher.java
Fixed
Show fixed
Hide fixed
From latest run https://jenkins.webtide.net/blue/organizations/jenkins/jetty.project/detail/PR-8597/10/tests org.eclipse.jetty.tests.distribution.DemoModulesTests.testJspDump([1] ee8) Test Failure
I wonder if this should be throwing, or not. |
@@ -126,8 +126,8 @@ public Resource resolve(String subUriPath) | |||
for (Resource res : _resources) | |||
{ | |||
addedResource = res.resolve(subUriPath); | |||
if (!addedResource.exists()) | |||
continue; | |||
if (addedResource == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think more changes below are needed for code clarity.
specifically if resources == null, can we just explicitly return null?
@@ -226,7 +226,7 @@ protected void doStart() throws Exception | |||
List<Path> files = new ArrayList<>(); | |||
for (Resource resource : _monitored) | |||
{ | |||
if (resource.exists() && Files.isReadable(resource.getPath())) | |||
if (resource != null && Files.isReadable(resource.getPath())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not adding null
s into _monitored
for non-existing resources, so this null check can go away.
for (Resource resource: resources) | ||
{ | ||
if (resource != null) | ||
_monitored.addAll(resources); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding the resources
collection for each resource?
return; | ||
} | ||
|
||
Resource resource = ResourceFactory.root().newResource(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Path
may require mounting, right? So this may lead to a mount leak if I'm not mistaken.
@@ -26,6 +28,14 @@ | |||
*/ | |||
public class MountedPathResource extends PathResource | |||
{ | |||
public static MountedPathResource of(URI uri) throws IOException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is public
needed?
@@ -47,6 +47,14 @@ public class PathResource extends Resource | |||
.with("jrt") | |||
.build(); | |||
|
|||
public static PathResource of(URI uri) throws IOException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is public
needed?
@@ -34,6 +44,18 @@ public class MountedPathResource extends PathResource | |||
containerUri = URIUtil.unwrapContainer(getURI()); | |||
} | |||
|
|||
MountedPathResource(Path path, URI uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the other constructor still needed?
…experiment-resource-resolve-null-on-notexist
…experiment-resource-resolve-null-on-notexist
…experiment-resource-resolve-null-on-notexist
…experiment-resource-resolve-null-on-notexist
…experiment-resource-resolve-null-on-notexist
Closing this large (in commit count) PR in favor of #8702 |
Resource.resolve(String)
return null if the resultingResource
would not exist.ResourceFactory.newResource()
(and similar methods) return null if the resultingResource
would not exist.