changeset 15509:1b9780bce9d3

Revert uses of addReads in several modules
author alanb
date Wed, 02 Mar 2016 15:39:38 +0000
parents 4b6e5280e43b
children 2fe9d4061c0c
files src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java src/java.logging/share/classes/java/util/logging/LogManager.java src/java.logging/share/classes/java/util/logging/MemoryHandler.java src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java src/java.naming/share/classes/com/sun/naming/internal/FactoryEnumeration.java src/java.naming/share/classes/com/sun/naming/internal/ResourceManager.java src/java.naming/share/classes/javax/naming/spi/NamingManager.java src/java.prefs/share/classes/java/util/prefs/Preferences.java src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncFactory.java src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java src/jdk.jartool/share/classes/jdk/security/jarsigner/JarSigner.java src/jdk.policytool/share/classes/sun/security/tools/policytool/PolicyTool.java
diffstat 17 files changed, 34 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java	Wed Mar 02 15:39:38 2016 +0000
@@ -33,7 +33,6 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.Module;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
@@ -807,8 +806,6 @@
          * of the given object.
          */
         public static Object newMarshalledObject(Object obj) throws IOException {
-            if (marshallObjectClass == null) return null;
-            ensureReadable(marshallObjectClass.getModule());
             try {
                 return marshallCtor == null ? null : marshallCtor.newInstance(obj);
             } catch (InstantiationException | IllegalAccessException x) {
@@ -826,8 +823,6 @@
          */
         public static Object getMarshalledObject(Object obj)
                 throws IOException, ClassNotFoundException {
-            if (marshallObjectClass == null) return null;
-            ensureReadable(marshallObjectClass.getModule());
             try {
                 return marshallGet == null ? null : marshallGet.invoke(obj);
             } catch (IllegalAccessException x) {
@@ -842,9 +837,5 @@
             }
         }
 
-        private static void ensureReadable(Module targetModule) {
-            Module thisModule = DataFlavor.class.getModule();
-            thisModule.addReads(targetModule);
-        }
     }
 }
--- a/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java	Wed Mar 02 15:39:38 2016 +0000
@@ -376,8 +376,6 @@
             }
         }
 
-        this.getClass().getModule().addReads(javaAgentClass.getModule());
-
         // the premain method should not be required to be public,
         // make it accessible so we can call it
         // Note: The spec says the following:
--- a/src/java.logging/share/classes/java/util/logging/LogManager.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.logging/share/classes/java/util/logging/LogManager.java	Wed Mar 02 15:39:38 2016 +0000
@@ -31,7 +31,6 @@
 import java.security.*;
 import java.lang.ref.ReferenceQueue;
 import java.lang.ref.WeakReference;
-import java.lang.reflect.Module;
 import java.util.concurrent.ConcurrentHashMap;
 import java.nio.file.Paths;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -233,12 +232,10 @@
                         try {
                             Class<?> clz = ClassLoader.getSystemClassLoader()
                                     .loadClass(cname);
-                            ensureReadable(clz.getModule());
                             mgr = (LogManager) clz.newInstance();
                         } catch (ClassNotFoundException ex) {
                             Class<?> clz = Thread.currentThread()
                                     .getContextClassLoader().loadClass(cname);
-                            ensureReadable(clz.getModule());
                             mgr = (LogManager) clz.newInstance();
                         }
                     }
@@ -980,7 +977,6 @@
         for (String type : names) {
             try {
                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(type);
-                ensureReadable(clz.getModule());
                 Handler hdl = (Handler) clz.newInstance();
                 // Check if there is a property defining the
                 // this handler's level.
@@ -1317,15 +1313,15 @@
                 // Instantiate the named class.  It is its constructor's
                 // responsibility to initialize the logging configuration, by
                 // calling readConfiguration(InputStream) with a suitable stream.
-                Class<?> clz;
                 try {
-                    clz = ClassLoader.getSystemClassLoader().loadClass(cname);
+                    Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
+                    clz.newInstance();
+                    return;
                 } catch (ClassNotFoundException ex) {
-                    clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
+                    Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(cname);
+                    clz.newInstance();
+                    return;
                 }
-                ensureReadable(clz.getModule());
-                clz.newInstance();
-                return;
             } catch (Exception ex) {
                 System.err.println("Logging configuration class \"" + cname + "\" failed");
                 System.err.println("" + ex);
@@ -1550,7 +1546,6 @@
                 for (String word : names) {
                     try {
                         Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(word);
-                ensureReadable(clz.getModule());
                         clz.newInstance();
                     } catch (Exception ex) {
                         System.err.println("Can't load config class \"" + word + "\"");
@@ -2298,7 +2293,6 @@
         try {
             if (val != null) {
                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val);
-                ensureReadable(clz.getModule());
                 return (Filter) clz.newInstance();
             }
         } catch (Exception ex) {
@@ -2320,7 +2314,6 @@
         try {
             if (val != null) {
                 Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(val);
-                ensureReadable(clz.getModule());
                 return (Formatter) clz.newInstance();
             }
         } catch (Exception ex) {
@@ -2617,10 +2610,6 @@
         if (t instanceof RuntimeException) throw (RuntimeException)t;
     }
 
-    static void ensureReadable(Module targetModule) {
-        LogManager.class.getModule().addReads(targetModule);
-    }
-
     /**
      * This class allows the {@link LoggingProviderImpl} to demand loggers on
      * behalf of system and application classes.
--- a/src/java.logging/share/classes/java/util/logging/MemoryHandler.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.logging/share/classes/java/util/logging/MemoryHandler.java	Wed Mar 02 15:39:38 2016 +0000
@@ -117,7 +117,6 @@
         Class<?> clz;
         try {
             clz = ClassLoader.getSystemClassLoader().loadClass(targetName);
-            LogManager.ensureReadable(clz.getModule());
             target = (Handler) clz.newInstance();
         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
             throw new RuntimeException("MemoryHandler can't load handler target \"" + targetName + "\"" , e);
--- a/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java	Wed Mar 02 15:39:38 2016 +0000
@@ -43,7 +43,6 @@
 import javax.naming.ldap.Control;
 
 import java.lang.reflect.Method;
-import java.lang.reflect.Module;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 import javax.net.SocketFactory;
@@ -262,11 +261,6 @@
                 (Class<? extends SocketFactory>)Obj.helper.loadClass(socketFactory);
             Method getDefault =
                 socketFactoryClass.getMethod("getDefault", new Class<?>[]{});
-
-            Module thisModule = Connection.class.getModule();
-            Module targetModule = socketFactoryClass.getModule();
-            thisModule.addReads(targetModule);
-
             SocketFactory factory = (SocketFactory) getDefault.invoke(null, new Object[]{});
 
             // create the socket
--- a/src/java.naming/share/classes/com/sun/naming/internal/FactoryEnumeration.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.naming/share/classes/com/sun/naming/internal/FactoryEnumeration.java	Wed Mar 02 15:39:38 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package com.sun.naming.internal;
 
-import java.lang.reflect.Module;
 import java.util.List;
 import javax.naming.NamingException;
 
@@ -86,11 +85,8 @@
                     Class<?> cls = Class.forName(className, true, loader);
                     answer = cls;
                 }
-                // Make the factory module readable to this module
-                Module me = ResourceManager.class.getModule();
-                me.addReads(((Class) answer).getModule());
                 // Instantiate Class to get factory
-                answer = ((Class<?>) answer).newInstance();
+                answer = ((Class) answer).newInstance();
                 ref = new NamedWeakReference<>(answer, className);
                 factories.set(posn-1, ref);  // replace Class object or null
                 return answer;
--- a/src/java.naming/share/classes/com/sun/naming/internal/ResourceManager.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.naming/share/classes/com/sun/naming/internal/ResourceManager.java	Wed Mar 02 15:39:38 2016 +0000
@@ -28,7 +28,6 @@
 import java.io.InputStream;
 import java.io.IOException;
 import java.lang.ref.WeakReference;
-import java.lang.reflect.Module;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
@@ -399,10 +398,8 @@
             while (factory == null && parser.hasMoreTokens()) {
                 className = parser.nextToken() + classSuffix;
                 try {
-                    Class<?> clazz = helper.loadClass(className, loader);
-                    Module me = ResourceManager.class.getModule();
-                    me.addReads(clazz.getModule());
-                    factory = clazz.newInstance();
+                    // System.out.println("loading " + className);
+                    factory = helper.loadClass(className, loader).newInstance();
                 } catch (InstantiationException e) {
                     NamingException ne =
                         new NamingException("Cannot instantiate " + className);
--- a/src/java.naming/share/classes/javax/naming/spi/NamingManager.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.naming/share/classes/javax/naming/spi/NamingManager.java	Wed Mar 02 15:39:38 2016 +0000
@@ -25,7 +25,6 @@
 
 package javax.naming.spi;
 
-import java.lang.reflect.Module;
 import java.net.MalformedURLException;
 import java.util.*;
 
@@ -160,12 +159,7 @@
             }
         }
 
-        if (clas != null) {
-            ensureReadable(clas.getModule());
-            return (ObjectFactory) clas.newInstance();
-        } else {
-            return null;
-        }
+        return (clas != null) ? (ObjectFactory) clas.newInstance() : null;
     }
 
 
@@ -716,9 +710,8 @@
 
             if (factory == null) {
                 try {
-                    Class<?> clazz = helper.loadClass(className);
-                    ensureReadable(clazz.getModule());
-                    factory = (InitialContextFactory) clazz.newInstance();
+                    factory = (InitialContextFactory)
+                            helper.loadClass(className).newInstance();
                 } catch (Exception e) {
                     NoInitialContextException ne =
                             new NoInitialContextException(
@@ -925,9 +918,4 @@
 
         return (answer != null) ? answer : obj;
     }
-
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = NamingManager.class.getModule();
-        thisModule.addReads(targetModule);
-    }
 }
--- a/src/java.prefs/share/classes/java/util/prefs/Preferences.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.prefs/share/classes/java/util/prefs/Preferences.java	Wed Mar 02 15:39:38 2016 +0000
@@ -28,7 +28,6 @@
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.lang.reflect.Module;
 import java.security.AccessController;
 import java.security.Permission;
 import java.security.PrivilegedAction;
@@ -238,37 +237,29 @@
             // not use the context classloader, to avoid being
             // dependent on the invoking thread.
             // Checking AllPermission also seems wrong.
-            Class<?> factoryClass = null;
             try {
-                factoryClass
-                    = Class.forName(factoryName, false,
-                        ClassLoader.getSystemClassLoader());
-            } catch (Exception e) {
-                // workaround for javaws, plugin,
-                // load factory class using non-system classloader
-                SecurityManager sm = System.getSecurityManager();
-                if (sm != null) {
-                    sm.checkPermission(new java.security.AllPermission());
+                return (PreferencesFactory)
+                    Class.forName(factoryName, false,
+                                  ClassLoader.getSystemClassLoader())
+                    .newInstance();
+            } catch (Exception ex) {
+                try {
+                    // workaround for javaws, plugin,
+                    // load factory class using non-system classloader
+                    SecurityManager sm = System.getSecurityManager();
+                    if (sm != null) {
+                        sm.checkPermission(new java.security.AllPermission());
+                    }
+                    return (PreferencesFactory)
+                        Class.forName(factoryName, false,
+                                      Thread.currentThread()
+                                      .getContextClassLoader())
+                        .newInstance();
+                } catch (Exception e) {
+                    throw new InternalError(
+                        "Can't instantiate Preferences factory "
+                        + factoryName, e);
                 }
-                try {
-                    ClassLoader loader
-                        = Thread.currentThread().getContextClassLoader();
-                    factoryClass = Class.forName(factoryName, false, loader);
-                } catch (Exception e2) {
-                    throw new InternalError(
-                        "Unable to load Preferences factory "
-                        + factoryName, e2);
-                }
-            }
-
-            try {
-                Module thisModule = Preferences.class.getModule();
-                thisModule.addReads(factoryClass.getModule());
-                return (PreferencesFactory) factoryClass.newInstance();
-            } catch (Exception e) {
-                throw new InternalError(
-                    "Can't instantiate Preferences factory "
-                    + factoryName, e);
             }
         }
 
--- a/src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java	Wed Mar 02 15:39:38 2016 +0000
@@ -25,7 +25,6 @@
 
 package com.sun.rowset;
 
-import java.lang.reflect.Module;
 import java.sql.*;
 import javax.sql.*;
 import java.io.*;
@@ -2963,7 +2962,6 @@
                 SQLData obj = null;
                 try {
                     ReflectUtil.checkPackageAccess(c);
-                    ensureReadable(c.getModule());
                     obj = (SQLData) c.newInstance();
                 } catch(Exception ex) {
                     throw new SQLException("Unable to Instantiate: ", ex);
@@ -2980,10 +2978,6 @@
         return value;
     }
 
-    private static void ensureReadable(Module targetModule) {
-        CachedRowSetImpl.class.getModule().addReads(targetModule);
-    }
-
     /**
      * Retrieves the value of the designated column in the current row
      * of this <code>CachedRowSetImpl</code> object as an
@@ -5716,7 +5710,6 @@
                 SQLData obj = null;
                 try {
                     ReflectUtil.checkPackageAccess(c);
-                    ensureReadable(c.getModule());
                     obj = (SQLData) c.newInstance();
                 } catch(Exception ex) {
                     throw new SQLException("Unable to Instantiate: ", ex);
--- a/src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java	Wed Mar 02 15:39:38 2016 +0000
@@ -574,7 +574,6 @@
                         SQLData obj = null;
                         try {
                             ReflectUtil.checkPackageAccess(c);
-                            CachedRowSetImpl.class.getModule().addReads(c.getModule());
                             obj = (SQLData)c.newInstance();
                         } catch (Exception ex) {
                             throw new SQLException("Unable to Instantiate: ", ex);
--- a/src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java	Wed Mar 02 15:39:38 2016 +0000
@@ -274,7 +274,6 @@
         }
 
         ReflectUtil.checkPackageAccess(factoryClass);
-        RowSetProvider.class.getModule().addReads(factoryClass.getModule());
         return factoryClass;
     }
 
--- a/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Wed Mar 02 15:39:38 2016 +0000
@@ -478,7 +478,6 @@
                 SQLData obj = null;
                 try {
                     ReflectUtil.checkPackageAccess(c);
-                    SQLInputImpl.class.getModule().addReads(c.getModule());
                     obj = (SQLData)c.newInstance();
                 } catch (Exception ex) {
                     throw new SQLException("Unable to Instantiate: ", ex);
--- a/src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncFactory.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncFactory.java	Wed Mar 02 15:39:38 2016 +0000
@@ -582,7 +582,6 @@
              * there.
              **/
             c = Class.forName(providerID, true, cl);
-            SyncFactory.class.getModule().addReads(c.getModule());
             return (SyncProvider) c.newInstance();
 
         } catch (IllegalAccessException e) {
--- a/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java	Wed Mar 02 15:39:38 2016 +0000
@@ -1447,9 +1447,6 @@
                             }
                             return null;
                         }
-
-                        // need to read the other module where the callback handler is in
-                        this.getClass().getModule().addReads(c.getModule());
                         return (CallbackHandler)c.newInstance();
                     }
                 });
--- a/src/jdk.jartool/share/classes/jdk/security/jarsigner/JarSigner.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/jdk.jartool/share/classes/jdk/security/jarsigner/JarSigner.java	Wed Mar 02 15:39:38 2016 +0000
@@ -1093,7 +1093,6 @@
         try {
             // attempt to find signer
             Class<?> signerClass = appClassLoader.loadClass(signerClassName);
-            JarSigner.class.getModule().addReads(signerClass.getModule());
             Object signer = signerClass.newInstance();
             return (ContentSigner) signer;
         } catch (ClassNotFoundException|InstantiationException|
--- a/src/jdk.policytool/share/classes/sun/security/tools/policytool/PolicyTool.java	Wed Mar 02 15:25:52 2016 +0000
+++ b/src/jdk.policytool/share/classes/sun/security/tools/policytool/PolicyTool.java	Wed Mar 02 15:39:38 2016 +0000
@@ -700,7 +700,6 @@
             break;
         }
         Object parameters[] = objects.toArray();
-        PolicyTool.class.getModule().addReads(pc.getModule());
         Permission p = (Permission)c.newInstance(parameters);
     }