harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r464656 - in /incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang: Class.java ClassLoader.java
Date Mon, 16 Oct 2006 20:42:23 GMT
Author: geirm
Date: Mon Oct 16 13:42:22 2006
New Revision: 464656

URL: http://svn.apache.org/viewvc?view=rev&rev=464656
Log:
HARMONY-1654

Pair of defects in j.l.Class, j.l.ClassLoader impls:
- Class.getResourceAsStream(null), Class.getResource(null), ClassLoader.getResource(null),
  ClassLoader.getResourceAsStream(null), ClassLoader.getSystemResource(null),
  ClassLoader.getSystemResourceAsStream(null) should throw NPE (Test1).
  Throwing the NulPointerException as demanded resolves the issue.
- According to the ClassLoader.getSystemClassLoader() spec, a "system class loader" serving
for
  start an application should automatically grant the exitVM permission
  to all code loaded from the application class path (Test2).
  j.l.ClassLoader$SystemClassLoader should grant it to resolve the issue. 

Ubuntu 6 - test cases, smoke, c-unit, ~kernel



Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java?view=diff&rev=464656&r1=464655&r2=464656
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
Mon Oct 16 13:42:22 2006
@@ -601,9 +601,6 @@
      * @com.intel.drl.spec_ref
      */
     public URL getResource(String resource) {
-        if (resource == null) {
-            return null;
-        }
         resource = getAbsoluteResource(resource);
         ClassLoader classLoader = VMClassRegistry.getClassLoader(this);
         return classLoader == null
@@ -615,9 +612,6 @@
      * @com.intel.drl.spec_ref
      */
     public InputStream getResourceAsStream(String resource) {
-        if (resource == null) {
-            return null;
-        }
         resource = getAbsoluteResource(resource);
         ClassLoader classLoader = VMClassRegistry.getClassLoader(this);
         return classLoader == null

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java?view=diff&rev=464656&r1=464655&r2=464656
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
Mon Oct 16 13:42:22 2006
@@ -240,19 +240,20 @@
      * @com.intel.drl.spec_ref 
      */
     public URL getResource(String name) {
+        String nm = name.toString();
         checkInitialized();
         URL foundResource = (parentClassLoader == null)
-            ? BootstrapLoader.findResource(name)
-            : parentClassLoader.getResource(name);
-        return foundResource == null ? findResource(name) : foundResource;
+            ? BootstrapLoader.findResource(nm)
+            : parentClassLoader.getResource(nm);
+        return foundResource == null ? findResource(nm) : foundResource;
     }
 
     /**
      * @com.intel.drl.spec_ref 
      */
     public InputStream getResourceAsStream(String name) {
+        URL foundResource = getResource(name);
         try {
-            URL foundResource = getResource(name);
             return foundResource.openStream();
         } catch (IOException e) {
         } catch (NullPointerException e) {
@@ -871,7 +872,38 @@
         }
     }
 
-    private static final class SystemClassLoader {
+    private static final class SystemClassLoader extends URLClassLoader {
+
+        private boolean checkingPackageAccess = false;
+
+        private SystemClassLoader(URL[] urls, ClassLoader parent) {
+            super(urls, parent);
+        }
+        
+        @Override
+        protected java.security.PermissionCollection getPermissions(CodeSource codesource)
{
+            java.security.PermissionCollection pc = super.getPermissions(codesource);
+            pc.add(org.apache.harmony.lang.RuntimePermissionCollection.EXIT_VM_PERMISSION);

+            return pc;
+        }
+        
+        @Override
+        protected synchronized Class<?> loadClass(String className,
+                boolean resolveClass) throws ClassNotFoundException {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null && !checkingPackageAccess) {
+                int index = className.lastIndexOf('.');
+                if (index > 0) { // skip if class is from a default package
+                    try {
+                        checkingPackageAccess = true;
+                        sm.checkPackageAccess(className.substring(0, index));
+                    } finally {
+                        checkingPackageAccess = false;
+                    }
+                }
+            }
+            return super.loadClass(className, resolveClass);
+        }
 
         private static URLClassLoader instance;
 
@@ -909,15 +941,8 @@
                     assert false: e.toString();
                 }
             }
-            instance = URLClassLoader.newInstance((URL[])urlList
+            instance = new SystemClassLoader((URL[])urlList
                 .toArray(new URL[urlList.size()]), null);
-        }
-
-        /**
-         * This class contains static methods only. So it should not be
-         * instantiated.
-         */
-        private SystemClassLoader() {
         }
 
         public static ClassLoader getInstance() {



Mime
View raw message