6485027: javac incorrectly handles relative paths in manifest classpath

Thu, 10 Feb 2011 15:05:33 -0800

author
jjg
date
Thu, 10 Feb 2011 15:05:33 -0800
changeset 874
e0c16199b2e0
parent 873
747a7601b6d6
child 875
bfeed79c70aa

6485027: javac incorrectly handles relative paths in manifest classpath
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/file/Paths.java file | annotate | diff | comparison | revisions
test/tools/javac/Paths/Class-Path.sh file | annotate | diff | comparison | revisions
test/tools/javac/Paths/Class-Path2.sh file | annotate | diff | comparison | revisions
test/tools/javac/Paths/Diagnostics.sh file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/file/Paths.java	Thu Feb 10 14:27:34 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java	Thu Feb 10 15:05:33 2011 -0800
     1.3 @@ -247,10 +247,16 @@
     1.4          public Path() { super(); }
     1.5  
     1.6          public Path addDirectories(String dirs, boolean warn) {
     1.7 -            if (dirs != null)
     1.8 -                for (File dir : getPathEntries(dirs))
     1.9 -                    addDirectory(dir, warn);
    1.10 -            return this;
    1.11 +            boolean prev = expandJarClassPaths;
    1.12 +            expandJarClassPaths = true;
    1.13 +            try {
    1.14 +                if (dirs != null)
    1.15 +                    for (File dir : getPathEntries(dirs))
    1.16 +                        addDirectory(dir, warn);
    1.17 +                return this;
    1.18 +            } finally {
    1.19 +                expandJarClassPaths = prev;
    1.20 +            }
    1.21          }
    1.22  
    1.23          public Path addDirectories(String dirs) {
     2.1 --- a/test/tools/javac/Paths/Class-Path.sh	Thu Feb 10 14:27:34 2011 -0800
     2.2 +++ b/test/tools/javac/Paths/Class-Path.sh	Thu Feb 10 15:05:33 2011 -0800
     2.3 @@ -1,7 +1,7 @@
     2.4  #!/bin/sh
     2.5  
     2.6  #
     2.7 -# Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
     2.8 +# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     2.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    2.10  #
    2.11  # This code is free software; you can redistribute it and/or modify it
    2.12 @@ -24,7 +24,7 @@
    2.13  #
    2.14  
    2.15  
    2.16 -# @test @(#)Class-Path.sh	1.3 03/10/31
    2.17 +# @test
    2.18  # @bug 4212732
    2.19  # @summary Test handling of the Class-Path attribute in jar file manifests
    2.20  # @author Martin Buchholz
    2.21 @@ -184,8 +184,8 @@
    2.22  #
    2.23  Success "$jar" cfe "Hello.jar" "Hello" Bye.class
    2.24  
    2.25 -# Jar creation and update when there is no manifest and inputfiles
    2.26 -specified
    2.27 +# Jar creation and update when there is no manifest and inputfiles 
    2.28 +# specified
    2.29  Failure "$jar" cvf "A.jar"
    2.30  Failure "$jar" uvf "A.jar"
    2.31  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/Paths/Class-Path2.sh	Thu Feb 10 15:05:33 2011 -0800
     3.3 @@ -0,0 +1,111 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     3.7 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8 +#
     3.9 +# This code is free software; you can redistribute it and/or modify it
    3.10 +# under the terms of the GNU General Public License version 2 only, as
    3.11 +# published by the Free Software Foundation.
    3.12 +#
    3.13 +# This code is distributed in the hope that it will be useful, but WITHOUT
    3.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.15 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.16 +# version 2 for more details (a copy is included in the LICENSE file that
    3.17 +# accompanied this code).
    3.18 +#
    3.19 +# You should have received a copy of the GNU General Public License version
    3.20 +# 2 along with this work; if not, write to the Free Software Foundation,
    3.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.22 +#
    3.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.24 +# or visit www.oracle.com if you need additional information or have any
    3.25 +# questions.
    3.26 +#
    3.27 +
    3.28 +# @test 
    3.29 +# @bug 4212732 6485027
    3.30 +# @summary Test handling of the Class-Path attribute in jar file manifests
    3.31 +# @author Martin Buchholz
    3.32 +#
    3.33 +# @run shell Class-Path2.sh
    3.34 +
    3.35 +# To run this test manually, simply do ./Class-Path2.sh
    3.36 +
    3.37 +. ${TESTSRC-.}/Util.sh
    3.38 +
    3.39 +set -u
    3.40 +
    3.41 +Cleanup() {
    3.42 +    Sys rm -rf pkg Main.java Main.class Main.jar jars
    3.43 +    Sys rm -rf MANIFEST.MF A.jar B.zip
    3.44 +}
    3.45 +
    3.46 +Cleanup
    3.47 +Sys mkdir pkg
    3.48 +
    3.49 +#----------------------------------------------------------------
    3.50 +# Create mutually referential jar files
    3.51 +#----------------------------------------------------------------
    3.52 +cat >pkg/A.java <<EOF
    3.53 +package pkg;
    3.54 +import pkg.B;
    3.55 +public class A {
    3.56 +    public static int f() { return B.g(); }
    3.57 +    public static int g() { return 0; }
    3.58 +}
    3.59 +EOF
    3.60 +
    3.61 +cat >pkg/B.java <<EOF
    3.62 +package pkg;
    3.63 +import pkg.A;
    3.64 +public class B {
    3.65 +    public static int f() { return A.g(); }
    3.66 +    public static int g() { return 0; }
    3.67 +}
    3.68 +EOF
    3.69 +
    3.70 +Sys "$javac" pkg/A.java pkg/B.java
    3.71 +
    3.72 +MkManifestWithClassPath "./sub/B.zip"
    3.73 +Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
    3.74 +
    3.75 +MkManifestWithClassPath "../A.jar"
    3.76 +Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class
    3.77 +
    3.78 +cat >Main.java <<EOF
    3.79 +import pkg.*;
    3.80 +public class Main {
    3.81 +    public static void main(String []a) { System.exit(A.f() + B.f()); }
    3.82 +}
    3.83 +EOF
    3.84 +
    3.85 +Sys rm -rf pkg
    3.86 +
    3.87 +Sys mkdir jars
    3.88 +Sys mkdir jars/sub/
    3.89 +Sys mv A.jar jars/.
    3.90 +Sys mv B.zip jars/sub/.
    3.91 +
    3.92 +#
    3.93 +# Test 1: Compiling 
    3.94 +#
    3.95 +
    3.96 +Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java
    3.97 +Success "$java"  ${TESTVMOPTS}     -cp "jars/A.jar${PS}." Main
    3.98 +
    3.99 +Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/sub/B.zip"       Main.java
   3.100 +Success "$java"  ${TESTVMOPTS}     -cp "jars/sub/B.zip${PS}." Main
   3.101 +
   3.102 +#
   3.103 +# Test 2: Use of extension directories is incorrect
   3.104 +#
   3.105 +
   3.106 +Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars          -cp None Main.java
   3.107 +Success "$java"  ${TESTVMOPTS}     -Djava.ext.dirs="jars" -cp .    Main
   3.108 +
   3.109 +Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars/sub          -cp None Main.java
   3.110 +Success "$java"  ${TESTVMOPTS}     -Djava.ext.dirs="jars/sub" -cp .    Main
   3.111 +
   3.112 +Cleanup
   3.113 +
   3.114 +Bottom Line
     4.1 --- a/test/tools/javac/Paths/Diagnostics.sh	Thu Feb 10 14:27:34 2011 -0800
     4.2 +++ b/test/tools/javac/Paths/Diagnostics.sh	Thu Feb 10 15:05:33 2011 -0800
     4.3 @@ -1,7 +1,7 @@
     4.4  #!/bin/sh
     4.5  
     4.6  #
     4.7 -# Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
     4.8 +# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     4.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4.10  #
    4.11  # This code is free software; you can redistribute it and/or modify it
    4.12 @@ -182,12 +182,12 @@
    4.13  No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
    4.14  
    4.15  #----------------------------------------------------------------
    4.16 -# Class-Path attribute ignored in extdirs or endorseddirs
    4.17 +# Class-Path attribute followed in extdirs or endorseddirs
    4.18  #----------------------------------------------------------------
    4.19  Sys mkdir jars
    4.20  Sys cp -p classesRefRef.jar jars/.
    4.21 -No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs      jars Main.java
    4.22 -No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java
    4.23 +   Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs      jars Main.java
    4.24 +   Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java
    4.25  
    4.26  #----------------------------------------------------------------
    4.27  # Bad Jar file in extdirs and endorseddirs should not be ignored

mercurial