-
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 - Resource resolve()
and newResource()
return null on resources that do not exist
#8702
Jetty 12 - Resource resolve()
and newResource()
return null on resources that do not exist
#8702
Conversation
resolve()
and newResource()
return null on resources that do not existresolve()
and newResource()
return null on resources that do not exist
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.
Generally I'm still not convinced that we really want to scatter null checks all over the code base. I also really don't like the implied suggestion that a non null resource does exist. That might be true soon after resolved, but it might not be true for a resource taken out of a collection some time after the resolution.
So I think regardless of returning null or not, I think we need some static methods that will do the null checking:
interface Resources
{
public static boolean exists(Resource r)
{
return r != null && r.exists();
}
public static boolean isDirectory(Resource r)
{
return r != null && r.isDirectory();
}
}
This style mimics the statics in Paths
and Files
(although I don't mind if they are on Resource
rather than a Resources
interface).
I'm also wondering if perhaps an Optional would be better than a null return. So resolve would always return a non null resource (even if it is a BadResource), but then we'd have a new method:
public Optional<Resource> resolveExisting(String subPath)
{
Resource resource = resolve(subPath);
if (resource.exists())
return Optional.of(resource);
return Optional.empty();
}
...-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java
Outdated
Show resolved
Hide resolved
...-core/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-keystore/src/main/config/modules/test-keystore.mod
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java
Outdated
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/ResourceCollection.java
Outdated
Show resolved
Hide resolved
...-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java
Outdated
Show resolved
Hide resolved
…resource-resolve-new-null-on-notexist
…resource-resolve-new-null-on-notexist
…resource-resolve-new-null-on-notexist
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java
Outdated
Show resolved
Hide resolved
…resource-resolve-new-null-on-notexist
…resource-resolve-new-null-on-notexist
…resource-resolve-new-null-on-notexist
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 like the statics... but a few niggles
public boolean isReadable() | ||
{ | ||
// always a directory, never readable | ||
return false; | ||
} |
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.
A directory can be readable, in that it's contents can be listed.
I can see an interpretation of isReadable
that means there is content available, but this is a change in semantics that I don't think we need. It is a valid check to ask a directory if it is readable or not. Perhaps this check could be made in the constructor?
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.
Asking "isReadable()" should be different than "isDirectory()".
Meaning if you are isDirectory() == true
then you have no need to call isReadable()
anyway.
If you look at usage, the isReadable()
checks are typically for places where we expect a non-directory that can be accessed and be read (eg: a file)
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 know that we used to check some directories for readability. I don't really see the need for changing this semantic. What does a directory that exists but is not actually readable on the file system look like? If all our directory handling code expects directories to not be readable, then we won't be able to distinguish this case?
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.
perhaps rename to hasContent
or hasReadableContent
if you want your semantic, to distinguish from the Files
method that can apply to a directory.
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.
Perhaps it should be canBeOpenForRead()
instead.
As it's not meant for "can we access" or "do we have read permissions".
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resources.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resources.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resources.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resources.java
Outdated
Show resolved
Hide resolved
…resource-resolve-new-null-on-notexist
Cleaned up version of PR #8597