Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 74931 invoked from network); 12 Jan 2009 03:07:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Jan 2009 03:07:58 -0000 Received: (qmail 48888 invoked by uid 500); 12 Jan 2009 03:07:57 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 48866 invoked by uid 500); 12 Jan 2009 03:07:57 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 48857 invoked by uid 99); 12 Jan 2009 03:07:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Jan 2009 19:07:57 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jan 2009 03:07:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8AE1A2388988; Sun, 11 Jan 2009 19:07:34 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@harmony.apache.org From: qiuxx@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090112030734.8AE1A2388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 + } + } }