harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r733590 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java main/java/org/apache/harmony/luni/util/ExternalMessages.properties test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java
Date Mon, 12 Jan 2009 03:07:34 GMT
Author: qiuxx
Date: Sun Jan 11 19:07:33 2009
New Revision: 733590

URL: http://svn.apache.org/viewvc?rev=733590&view=rev
Log:
Apply for HARMONY-6042,([classlib][luni] Classes can not be loaded correctly in sealed-packages)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java?rev=733590&r1=733589&r2=733590&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
Sun Jan 11 19:07:33 2009
@@ -418,18 +418,16 @@
                                 null, null, null, null, null);
                     }
                 } else {
-                    boolean exception = false;
+                    boolean exception = packageObj.isSealed();
                     if (manifest != null) {
                         if (isSealed(manifest, packageName + "/")) {
                             exception = !packageObj
                                     .isSealed(codeSourceUrl);
                         }
-                    } else {
-                        exception = packageObj.isSealed();
                     }
                     if (exception) {
                         throw new SecurityException(Msg
-                                .getString("K004c")); //$NON-NLS-1$
+                                .getString("K0352", packageName)); //$NON-NLS-1$
                     }
                 }
             }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?rev=733590&r1=733589&r2=733590&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
Sun Jan 11 19:07:33 2009
@@ -286,6 +286,7 @@
 K034d=method has not been implemented yet
 K034e=Build rules empty
 K0351=format is null
+K0352=package is sealed
 KA000=Line too long
 KA001=Argument must not be null
 KA002=Unshared read of back reference

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java?rev=733590&r1=733589&r2=733590&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/PackageTest.java
Sun Jan 11 19:07:33 2009
@@ -17,7 +17,7 @@
 package org.apache.harmony.luni.tests.java.lang;
 
 import java.io.File;
-import java.lang.reflect.Method;
+import java.io.InputStream;
 import java.net.URL;
 import java.net.URLClassLoader;
 
@@ -290,4 +290,101 @@
         assertTrue("Package toString returns wrong string", p.toString()
                 .length() > 0);
     }
+    
+    public void test_SealedPackage_forName() throws Exception {
+        Support_Resources.copyFile(resources, "Package", "hyts_c.jar");
+        Support_Resources.copyFile(resources, "Package", "hyts_d.jar");
+        Support_Resources.copyFile(resources, "Package", "hyts_d1.jar");
+        Support_Resources.copyFile(resources, "Package", "hyts_d2.jar");
+
+        URL resourceURL1 = new URL("file:/" + resPath + "/Package/hyts_c.jar");
+        URL resourceURL2 = new URL("file:/" + resPath + "/Package/hyts_d.jar");
+        URL resourceURL3 = new URL("file:/" + resPath + "/Package/hyts_d1.jar");
+        URL resourceURL4 = new URL("file:/" + resPath + "/Package/hyts_d2.jar");
+        URL resourceURL5 = new URL("file:/" + resPath + "/");
+
+        URLClassLoader uclClassLoader;
+        // load from the sealed jar, then an unsealed jar with no manifest
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL2 }, null);
+        Class.forName("p.C", true, uclClassLoader);
+        try {
+            Class.forName("p.D", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // setup for next test
+        Support_Resources.copyFile(resources, "p", "");
+        InputStream in = uclClassLoader.getResourceAsStream("p/D.class");
+        Support_Resources.copyLocalFileto(new File(resources.toString(),
+                "p/D.class"), in);
+
+        // load from a sealed jar, then the directory
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL5 }, null);
+        Class.forName("p.C", true, uclClassLoader);
+        try {
+            Class.forName("p.D", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // load from a directory, then the sealed jar
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL5 }, null);
+        Class.forName("p.D", true, uclClassLoader);
+        try {
+            Class.forName("p.C", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // load from an unsealed jar with no manifest, then the sealed jar
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL2 }, null);
+        Class.forName("p.D", true, uclClassLoader);
+        try {
+            Class.forName("p.C", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // load from an unsealed jar with a manifest, then the sealed jar
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL3 }, null);
+        Class.forName("p.C", true, uclClassLoader);
+        try {
+            Class.forName("p.D", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // load from an sealed jar, then the unsealed jar with a manifest
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL3 }, null);
+        Class.forName("p.D", true, uclClassLoader);
+        try {
+            Class.forName("p.C", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+
+        // load from the sealed jar, then another sealed jar
+        uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1,
+                resourceURL4 }, null);
+        Class.forName("p.C", true, uclClassLoader);
+        try {
+            Class.forName("p.D", true, uclClassLoader);
+            fail("should throw SecurityException");
+        } catch (SecurityException e) {
+            // Expected
+        }
+    }
 }



Mime
View raw message