-
Notifications
You must be signed in to change notification settings - Fork 6k
8358729: jdk/internal/loader/URLClassPath/ClassnameCharTest.java depends on Applet #25703
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
@justin-curtis-lu This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 133 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@justin-curtis-lu The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
Hello Justin, how was the class file with those space characters in the method name and the class name generated? If we can do that within the test itself then I think it should also allow us to generate that JAR file dynamically in the test instead of having to continue maintaining this binary file. |
Hi Jai, I had trouble creating class "fo o" through traditional means, so I used the ClassFile API to create those class files. Using |
Use of ClassFile API I think is a good approach.
If you run into trouble using the |
Hi Jai, ab8785c dynamically creates the class and jar file. I decided not to write "手册" as a Jar entry, since it's commented out in the test. It should be trivial to dynamically create an entry for that class in the future if needed. |
* @summary cannot load class names containing some JSR 202 characters; | ||
* plugin does not escape unicode character in http request | ||
* @library /test/lib | ||
* @modules java.base/sun.net.www | ||
* jdk.httpserver | ||
* @compile -XDignore.symbol.file=true ClassnameCharTest.java |
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.
Hello Justin, this is pre-existing but since we are updating this test, I think it better to remove this @compile
line altogether. It isn't needed for this test.
throw new ClassNotFoundException(name, e.getException()); | ||
} | ||
} catch (Exception _) {} | ||
throw new ClassNotFoundException(name); |
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 we should propagate the underlying cause too, to help debugging if it fails for whatever reason. So something like:
catch (Exception e) {
throw new ClassNotFoundException(name, e);
}
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.
Good point, also gave the other exception a more helpful message as well.
import sun.net.www.ParseUtil; | ||
|
||
public class ClassnameCharTest { | ||
static String FNPrefix = System.getProperty("test.src", ".") + File.separator; | ||
static File classesJar = new File(FNPrefix + "testclasses.jar"); | ||
private static final String JAR_PATH = Utils.TEST_CLASSES + Utils.FILE_SEPARATOR + "testclasses.jar"; |
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 it would be better to use java.nio.file.Path
which is like:
private static final Path JAR_PATH = Path.of(".").resolve("testclasses.jar");
That way we don't have to reference the Utils.TEST_CLASSES
. Path.of(".")
will end up being the scratch directory of the test so jtreg can then retain this JAR file if the test fails for any reason.
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.
Thanks, this is cleaner.
static String FNPrefix = System.getProperty("test.src", ".") + File.separator; | ||
static File classesJar = new File(FNPrefix + "testclasses.jar"); | ||
private static final String JAR_PATH = Utils.TEST_CLASSES + Utils.FILE_SEPARATOR + "testclasses.jar"; | ||
static File classesJar = new File(JAR_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.
If we switch to using Path
for JAR_PATH
, like I suggest above, then we can get rid of this field altogether and at the call site, we can just to JAR_PATH.toFile()
if we want to have a File
instance corresponding to that Path
.
Thank you Justin for these changes. Overall I believe these are the correct changes to do. I have some review suggestions which I've added inline. I went back and looked at the JDK-5017871 issue through which the |
} | ||
} catch (PrivilegedActionException e) { | ||
throw new ClassNotFoundException(name, e.getException()); | ||
// protocol/host/port mismatch, fail with RuntimeExc |
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.
Looks like a typo - should have been RuntimeException
?
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.
Hello Justin, the changes look OK to me. Please wait for a Lance to take a look too.
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.
Thank you for the updates Justin.
Looks good overall. If you have to update this test again, it might be worthwhile considering converting to a junit test
} | ||
} catch (PrivilegedActionException e) { | ||
throw new ClassNotFoundException(name, e.getException()); | ||
// protocol/host/port mismatch, fail with RuntimeExc |
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.
Typo RuntimeExc?
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.
02c76c7 corrects the comment typo and also makes a conversion of this test to JUnit.
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.
Thank you for the changes Justin
@BeforeAll | ||
static void setup() throws IOException { | ||
var bytes = ClassFile.of().build(ClassDesc.of("fo o"), _ -> {}); | ||
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(JAR_PATH.toFile()))) { |
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.
Suggestion: The original test used testclasses.jar to provide two class files with invalid names packaged in a jar. Since you now dynamically construct the class files, there is no need to write them to disk as a jar. Why not have a Map<String,byte[]), mapping a resource path to bytes, to store all used class files in memory.
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.
Thanks, I think we can make this simplification because the original version of this test used to test directly against a "fo o.class" binary file, and changed overtime to adapt the jar. (Thanks @jaikiran for confirming). I updated it such that we just read the class file bytes directly, and all JAR related logic is dropped. I did not put it in a map, since the second class is commented out, and we have been testing only "fo o" for quite some time now.
Maybe labelling this test with |
return super.findClass(name); | ||
} catch (ClassNotFoundException e) { | ||
} | ||
|
||
// Otherwise, try loading the class from the code base URL | ||
// final String path = name.replace('.', '/').concat(".class").concat(cookie); | ||
String encodedName = ParseUtil.encodePath(name.replace('.', '/'), false); | ||
final String path = (new StringBuffer(encodedName)).append(".class").append(cookie).toString(); |
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.
Suggestion: final String path = encodedName + ".class" + cookie;
, avoiding StringBuffer
I am still wondering what this (old) test tries to proof. It is filed below jdk.onternal.loader.URLClassPath but doesn't use or test URLClassPath, and it succeeds to construct a Class with an invalid name "fo o". |
URLClassPath is used in URLClassLoader, so I think this is OK in the current test structure. In any case, any re-examination would need to be done in a separate issue. The scope of this PR is to simply remove the remnants of Applet. |
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.
Thank you for the updates Justin. This looks good to me.
Please review this PR which finishes Applet removal for the test: jdk/internal/loader/URLClassPath/ClassnameCharTest.java.
testclasses.jar
is updated such that the two classes no longer extend Applet.The bug description of JDK-8358729 contains the original
javap
output for those classes.Additionally, the security APIs that were marked for removal are also removed from this test as well.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25703/head:pull/25703
$ git checkout pull/25703
Update a local copy of the PR:
$ git checkout pull/25703
$ git pull https://git.openjdk.org/jdk.git pull/25703/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25703
View PR using the GUI difftool:
$ git pr show -t 25703
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25703.diff
Using Webrev
Link to Webrev Comment