RFR(M): JDK-8165500: TestJpsJar shouldn't jar all test.classpath directories

Daniel Fuchs daniel.fuchs at oracle.com
Fri Sep 23 09:48:37 UTC 2016


Hi Dmitry,

There's a potential bug here. If two directories in the
classpath contains two different versions of A.class,
then the wrong version (the one that comes last) will
be included in the jar:

LingeredAppForJps::buildJar

  109         for (String path : testClassPath.split(File.pathSeparator)) {
  110             String classFullName = path + File.separator + 
className + ".class";
  111             File f = new File(classFullName);
  112             if (f.exists()) {
  113               jarArgs.add("-C");
  114               jarArgs.add(path);
  115               jarArgs.add(".");
  116               System.out.println("INFO: scheduled to jar " + path);
  117             }
  118         }

To be more exact you should probably go through the list
in reverse order:

String[] paths = testClassPath.split(File.pathSeparator);
for (int i = paths.length ; --i >= 0 ; ) {
     String path = paths[i];
     String classFullName = ...;
     ...
}

or alternatively, keep your loop as it is but break out of it
as soon as you found the class you're looking for (I don't
know whether that would be the right solution though, I am
not familiar with these tests), or yet again keep on looping
but throw an exception if you encounter the class twice for
a different path.

best regards,

-- daniel

On 23/09/16 10:01, Dmitry Samersoff wrote:
> Everybody,
>
> Please, review:
>
> http://cr.openjdk.java.net/~dsamersoff/JDK-8165500/webrev.02/
>
> I refactored the test to improve stability and simplify further
> debugging.
>
> Testing: rbt
>
> PS: Diffs is messy, so pleas look at raw files.
>
> -Dmitry
>



More information about the serviceability-dev mailing list