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

The ClassLoader used to load annotation processors does not return directories from getResource/getResources methods, while normal ClassLoaders do - fixing. #6466

Merged

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Sep 18, 2023

Fixes the problem noted in the subject.


^Add meaningful description above

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

…rectories from getResource/getResources methods, while normal ClassLoaders do - fixing.
@lahodaj lahodaj added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Sep 18, 2023
@lahodaj lahodaj added this to the NB20 milestone Sep 18, 2023
return new URI ("jar:"+zipURI.toString()+"!/"+resourceName); //NOI18N
} catch (URISyntaxException e) {
//Need to encode the resName part (slower)
final StringBuilder sb = new StringBuilder ();
Copy link
Contributor

Choose a reason for hiding this comment

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

how about?

final StringBuilder sb = new StringBuilder (100).append("jar:").append(zipURI).append("!/");

and then just

return new URI(sb.toString);

}
}
return new URI("jar:"+zipURI.toString()+"!/"+sb.toString()); //NOI18N
} catch (final UnsupportedEncodingException e2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about ?

} catch (final UnsupportedEncodingException | URISyntaxException e2) {

final StringBuilder sb = new StringBuilder ();
final String[] elements = resourceName.split("/"); //NOI18N
try {
for (int i = 0; i< elements.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about for-each loop?

Copy link
Contributor

@dbalek dbalek left a comment

Choose a reason for hiding this comment

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

Thanks!

for (int i = 0; i< elements.length; i++) {
String element = elements[i];
element = URLEncoder.encode(element, "UTF-8"); //NOI18N
element = element.replace("+", "%20"); //NOI18N
Copy link
Member

Choose a reason for hiding this comment

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

Replacing "+" with URL-encoded space ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

URLEncoder.encode apparently replaces spaces with +. So this merely undoes that.

Copy link
Member

Choose a reason for hiding this comment

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

Because URLEncoder is not designed for encoding URLs. Are you sure that's the only possible problematic character? There are libraries in NetBeans already that could properly encode the path if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems space is the only character:
https://github.com/openjdk/jdk/blob/670b4567cf8229c9fd40c639a04dd1f1b7cfd551/src/java.base/share/classes/java/net/URLEncoder.java#L233

Please note this code is merely moved from one place to another, verbatim. I am not really confident to change that code, unless there's a bug in it that needs fixing.

Copy link
Member

Choose a reason for hiding this comment

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

OK, makes sense. I think other than space, it might just be escaping more than it needs to in this context.

@arvindaprameya
Copy link

Thank you for doing this , approved

@lahodaj lahodaj merged commit a2e110a into apache:master Sep 21, 2023
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants