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

Jetty 12 - Issue #8474 - return null on resolve() if resource doesn't exist #8597

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Sep 16, 2022

  • makes Resource.resolve(String) return null if the resulting Resource would not exist.
  • makes ResourceFactory.newResource() (and similar methods) return null if the resulting Resource would not exist.

@joakime joakime requested a review from sbordet September 16, 2022 16:56
@joakime
Copy link
Contributor Author

joakime commented Sep 16, 2022

@sbordet here's the minimal change to have PathResource.resolve() behave the same as ResourceCollection.resolve().

Copy link
Contributor

@gregw gregw left a 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.

@joakime joakime force-pushed the fix/jetty-12-experiment-resource-resolve-null-on-notexist branch from b277dac to 7f86ec1 Compare September 22, 2022 11:02
@joakime
Copy link
Contributor Author

joakime commented Sep 22, 2022

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)

@joakime
Copy link
Contributor Author

joakime commented Sep 22, 2022

The removal of exist() has not been done on this PR.

@gregw
Copy link
Contributor

gregw commented Sep 23, 2022

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)

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.

@joakime joakime self-assigned this Sep 23, 2022
@@ -252,30 +259,25 @@ public static Stream<Arguments> scenarios() throws Exception

public WorkDir workDir;

@Disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to revisit this

@joakime
Copy link
Contributor Author

joakime commented Sep 29, 2022

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

java.lang.IllegalArgumentException: KeyStore Path does not exist: /home/jenkins/agent/workspace/jetty.project_PR-8597
  /tests/test-distribution/test-distribution-common/target/tests/test-bases/jetty_base_5828043306936187437/etc/test-keystore.p12

I wonder if this should be throwing, or not.
I'm leaning towards throwing. (and fixing the testcase to actually have a keystore)

@sbordet and @lorban what do you think?

@@ -126,8 +126,8 @@ public Resource resolve(String subUriPath)
for (Resource res : _resources)
{
addedResource = res.resolve(subUriPath);
if (!addedResource.exists())
continue;
if (addedResource == null)
Copy link
Contributor

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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not adding nulls into _monitored for non-existing resources, so this null check can go away.

for (Resource resource: resources)
{
if (resource != null)
_monitored.addAll(resources);
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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?

@joakime joakime marked this pull request as ready for review October 7, 2022 16:42
@joakime joakime changed the title Jetty 12 - EXPERIMENT - Issue #8474 - return null on resolve() if resource doesn't exist Jetty 12 - Issue #8474 - return null on resolve() if resource doesn't exist Oct 7, 2022
@joakime joakime requested review from lorban and gregw October 7, 2022 16:46
…experiment-resource-resolve-null-on-notexist
@joakime
Copy link
Contributor Author

joakime commented Oct 10, 2022

Closing this large (in commit count) PR in favor of #8702

@joakime joakime closed this Oct 10, 2022
@joakime joakime deleted the fix/jetty-12-experiment-resource-resolve-null-on-notexist branch October 27, 2022 18:17
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.

3 participants