changeset 13349:a69d4f3516f7

Change Module#addReads to not do a permission check when adding a read edge from the caller module
author alanb
date Sat, 11 Jul 2015 09:39:22 +0100
parents 03eb170ea55d
children e02895df5905
files src/java.base/share/classes/java/lang/reflect/Module.java src/java.base/share/classes/java/security/UnresolvedPermission.java src/java.base/share/classes/javax/security/auth/login/LoginContext.java src/java.base/share/conf/security/java.policy src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java src/java.desktop/share/classes/com/sun/beans/util/Modules.java src/java.desktop/share/classes/java/awt/Cursor.java src/java.desktop/share/classes/java/awt/Toolkit.java src/java.desktop/share/classes/javax/swing/UIManager.java src/java.logging/share/classes/java/util/logging/LogManager.java src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java src/java.management/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java src/java.management/share/classes/com/sun/jmx/util/Modules.java src/java.management/share/classes/javax/management/MBeanServerFactory.java src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java src/java.management/share/classes/sun/management/MappedMXBeanType.java src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java src/java.naming/share/classes/javax/naming/spi/NamingManager.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
diffstat 22 files changed, 45 insertions(+), 187 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/reflect/Module.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.base/share/classes/java/lang/reflect/Module.java	Sat Jul 11 09:39:22 2015 +0100
@@ -54,6 +54,8 @@
 import sun.misc.JavaLangReflectAccess;
 import sun.misc.SharedSecrets;
 import sun.misc.Unsafe;
+import sun.reflect.CallerSensitive;
+import sun.reflect.Reflection;
 import sun.security.util.SecurityConstants;
 
 /**
@@ -242,10 +244,11 @@
      * reads all unnamed modules (both present and future) in the Java
      * virtual machine. </p>
      *
-     * <p> If there is a security manager then its {@code checkPermission}
+     * <p> If there is a security manager, and the caller of this method is not
+     * in this module, then the security manager's {@code checkPermission}
      * method is called with a {@code ReflectPermission("addReadsModule")}
-     * permission to check that the caller is allowed to change the
-     * readability graph. </p>
+     * permission to check that the caller is allowed to change the readability
+     * graph. </p>
      *
      * @return this module
      *
@@ -254,13 +257,19 @@
      *
      * @see #canRead
      */
+    @CallerSensitive
     public Module addReads(Module target) {
         if (target != this && this.isNamed()) {
+
             SecurityManager sm = System.getSecurityManager();
             if (sm != null) {
-                ReflectPermission perm = new ReflectPermission("addReadsModule");
-                sm.checkPermission(perm);
+                Module caller = Reflection.getCallerClass().getModule();
+                if (caller != this) {
+                    ReflectPermission perm = new ReflectPermission("addReadsModule");
+                    sm.checkPermission(perm);
+                }
             }
+
             implAddReads(target, true);
         }
         return this;
--- a/src/java.base/share/classes/java/security/UnresolvedPermission.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.base/share/classes/java/security/UnresolvedPermission.java	Sat Jul 11 09:39:22 2015 +0100
@@ -247,14 +247,8 @@
         try {
             Class<?> pc = p.getClass();
 
-            // Allow the base module to read the permission's module
-            Module pm = pc.getModule();
-            Module base = Object.class.getModule();
-            PrivilegedAction<Void> pa = () -> {
-                base.addReads(pm);
-                return null;
-            };
-            AccessController.doPrivileged(pa);
+            // The module with the permission class must be readable
+            this.getClass().getModule().addReads(pc.getModule());
 
             if (name == null && actions == null) {
                 try {
--- a/src/java.base/share/classes/javax/security/auth/login/LoginContext.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.base/share/classes/javax/security/auth/login/LoginContext.java	Sat Jul 11 09:39:22 2015 +0100
@@ -27,7 +27,6 @@
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.lang.reflect.Module;
 import java.util.Map;
 import java.util.HashMap;
 import java.text.MessageFormat;
@@ -288,13 +287,6 @@
         });
     }
 
-    private static void addReadsToBase(Class<?> c) {
-        Module base = Object.class.getModule();
-        Module target = c.getModule();
-        AccessController.doPrivileged((PrivilegedAction<Void>)
-                () -> { base.addReads(target); return null; });
-    }
-
     private void loadDefaultCallbackHandler() throws LoginException {
 
         // get the default handler class
@@ -312,7 +304,7 @@
                     Class<? extends CallbackHandler> c = Class.forName(
                             defaultHandler, true,
                             finalLoader).asSubclass(CallbackHandler.class);
-                    addReadsToBase(c);
+                    this.getClass().getModule().addReads(c.getModule());
                     return c.newInstance();
                 }
             });
--- a/src/java.base/share/conf/security/java.policy	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.base/share/conf/security/java.policy	Sat Jul 11 09:39:22 2015 +0100
@@ -56,8 +56,6 @@
         permission java.security.SecurityPermission "removeProviderProperty.*";
         permission java.security.SecurityPermission "getProperty.auth.login.defaultCallbackHandler";
         permission java.security.SecurityPermission "authProvider.*";
-        // Needed for creating callback handlers
-        permission java.lang.reflect.ReflectPermission "addReadsModule";
         // Needed for reading PKCS11 config file and NSS library check
         permission java.io.FilePermission "<<ALL FILES>>", "read";
 };
@@ -77,7 +75,6 @@
         permission java.lang.RuntimePermission "accessClassInPackage.com.sun.istack.internal";
         permission java.lang.RuntimePermission "accessClassInPackage.com.sun.istack.internal.*";
         permission java.lang.RuntimePermission "accessDeclaredMembers";
-        permission java.lang.reflect.ReflectPermission "addReadsModule";
         permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
         permission java.util.PropertyPermission "*", "read";
 };
--- a/src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.datatransfer/share/classes/sun/datatransfer/DataFlavorUtil.java	Sat Jul 11 09:39:22 2015 +0100
@@ -40,8 +40,6 @@
 import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -846,9 +844,7 @@
 
         private static void ensureReadable(Module targetModule) {
             Module thisModule = DataFlavor.class.getModule();
-            PrivilegedAction<Void> pa =
-                    () -> { thisModule.addReads(targetModule); return null; };
-            AccessController.doPrivileged(pa);
+            thisModule.addReads(targetModule);
         }
     }
 }
--- a/src/java.desktop/share/classes/com/sun/beans/util/Modules.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.desktop/share/classes/com/sun/beans/util/Modules.java	Sat Jul 11 09:39:22 2015 +0100
@@ -25,8 +25,6 @@
 package com.sun.beans.util;
 
 import java.beans.Beans;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.lang.reflect.Module;
 
 public final class Modules {
@@ -36,12 +34,7 @@
      * Ensures that the java.desktop module reads the targert module.
      */
     public static void ensureReadable(Module targetModule) {
-        Module beansModule = Beans.class.getModule();
-        if (beansModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { beansModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
+        Beans.class.getModule().addReads(targetModule);
     }
 
     /**
--- a/src/java.desktop/share/classes/java/awt/Cursor.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.desktop/share/classes/java/awt/Cursor.java	Sat Jul 11 09:39:22 2015 +0100
@@ -330,12 +330,12 @@
             } catch (NumberFormatException nfe) {
                 throw new AWTException("failed to parse hotspot property for cursor: " + name);
             }
-                final Toolkit toolkit = Toolkit.getDefaultToolkit();
-                final String file = RESOURCE_PREFIX + fileName;
+            final Toolkit toolkit = Toolkit.getDefaultToolkit();
+            final String file = RESOURCE_PREFIX + fileName;
             final InputStream in = AccessController.doPrivileged(
                     (PrivilegedAction<InputStream>) () -> {
                         return Cursor.class.getResourceAsStream(file);
-                        });
+                    });
             try (in) {
                 Image image = toolkit.createImage(in.readAllBytes());
                 cursor = toolkit.createCustomCursor(image, hotPoint, localized);
--- a/src/java.desktop/share/classes/java/awt/Toolkit.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.desktop/share/classes/java/awt/Toolkit.java	Sat Jul 11 09:39:22 2015 +0100
@@ -39,7 +39,6 @@
 import java.beans.PropertyChangeSupport;
 import java.io.File;
 import java.io.FileInputStream;
-import java.lang.reflect.Module;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.EventListener;
@@ -466,7 +465,7 @@
     private static void fallbackToLoadClassForAT(String atName) {
         try {
             Class<?> c = Class.forName(atName, false, ClassLoader.getSystemClassLoader());
-            ensureReadable(c.getModule());
+            Toolkit.class.getModule().addReads(c.getModule());
             c.newInstance();
         } catch (ClassNotFoundException e) {
             newAWTError(e, "Assistive Technology not found: " + atName);
@@ -479,13 +478,6 @@
         }
     }
 
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = Toolkit.class.getModule();
-        PrivilegedAction<Void> pa =
-                () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
-
     /**
      * Loads accessibility support using the property assistive_technologies.
      * The form is assistive_technologies= followed by a comma-separated list of
--- a/src/java.desktop/share/classes/javax/swing/UIManager.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.desktop/share/classes/javax/swing/UIManager.java	Sat Jul 11 09:39:22 2015 +0100
@@ -59,7 +59,6 @@
 import sun.security.action.GetPropertyAction;
 import sun.swing.SwingUtilities2;
 import java.lang.reflect.Method;
-import java.lang.reflect.Module;
 import java.util.HashMap;
 import sun.awt.AppContext;
 import sun.awt.AWTAccessor;
@@ -584,7 +583,7 @@
         }
         else {
             Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
-            ensureReadable(lnfClass.getModule());
+            UIManager.class.getModule().addReads(lnfClass.getModule());
             setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));
         }
     }
@@ -1053,7 +1052,7 @@
             String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
             try {
                 Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
-                ensureReadable(lnfClass.getModule());
+                UIManager.class.getModule().addReads(lnfClass.getModule());
                 multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();
             } catch (Exception exc) {
                 System.err.println("UIManager: failed loading " + className);
@@ -1500,15 +1499,4 @@
         AWTAccessor.getComponentAccessor().
             setRequestFocusController(JComponent.focusController);
     }
-
-    /**
-     * The java.desktop module needs to read the module with the LnF
-     * class.
-     */
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = UIManager.class.getModule();
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
 }
--- a/src/java.logging/share/classes/java/util/logging/LogManager.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.logging/share/classes/java/util/logging/LogManager.java	Sat Jul 11 09:39:22 2015 +0100
@@ -1927,12 +1927,7 @@
     }
 
     static void ensureReadable(Module targetModule) {
-        Module thisModule = LogManager.class.getModule();
-        if (thisModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
+        LogManager.class.getModule().addReads(targetModule);
     }
 
 }
--- a/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java	Sat Jul 11 09:39:22 2015 +0100
@@ -30,7 +30,6 @@
 
 import static javax.management.openmbean.SimpleType.*;
 
-import com.sun.jmx.util.Modules;
 import com.sun.jmx.remote.util.EnvHelp;
 
 import java.io.InvalidObjectException;
@@ -42,6 +41,7 @@
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Module;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
@@ -656,7 +656,7 @@
                 throws InvalidObjectException {
             final Object[] openArray = (Object[]) openValue;
             final Collection<Object> valueCollection;
-            Modules.ensureReadable(collectionClass.getModule());
+            ensureReadable(collectionClass.getModule());
             try {
                 valueCollection = cast(collectionClass.newInstance());
             } catch (Exception e) {
@@ -1117,7 +1117,7 @@
             try {
                 final Class<?> targetClass = getTargetClass();
                 ReflectUtil.checkPackageAccess(targetClass);
-                Modules.ensureReadable(targetClass.getModule());
+                ensureReadable(targetClass.getModule());
                 o = targetClass.newInstance();
                 for (int i = 0; i < itemNames.length; i++) {
                     if (cd.containsKey(itemNames[i])) {
@@ -1331,7 +1331,7 @@
                     params[index] = javaItem;
             }
 
-            Modules.ensureReadable(max.constructor.getDeclaringClass().getModule());
+            ensureReadable(max.constructor.getDeclaringClass().getModule());
             try {
                 ReflectUtil.checkPackageAccess(max.constructor.getDeclaringClass());
                 return max.constructor.newInstance(params);
@@ -1500,6 +1500,10 @@
         return rest;
     }
 
+    private static void ensureReadable(Module m) {
+        DefaultMXBeanMappingFactory.class.getModule().addReads(m);
+    }
+
     private final static Map<Type, Type> inProgress = newIdentityHashMap();
     // really an IdentityHashSet but that doesn't exist
 }
--- a/src/java.management/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.management/share/classes/com/sun/jmx/mbeanserver/MBeanInstantiator.java	Sat Jul 11 09:39:22 2015 +0100
@@ -55,8 +55,6 @@
 import sun.reflect.misc.ConstructorUtil;
 import sun.reflect.misc.ReflectUtil;
 
-import com.sun.jmx.util.Modules;
-
 /**
  * Implements the MBeanInstantiator interface. Provides methods for
  * instantiating objects, finding the class given its name and using
@@ -761,13 +759,13 @@
     }
 
     private static void ensureClassAccess(Class<?> clazz)
-            throws IllegalAccessException
+        throws IllegalAccessException
     {
         int mod = clazz.getModifiers();
         if (!Modifier.isPublic(mod)) {
             throw new IllegalAccessException("Class is not public and can't be instantiated");
         }
-        Modules.ensureReadable(clazz.getModule());
+        MBeanInstantiator.class.getModule().addReads(clazz.getModule());
     }
 
     private ClassLoader getClassLoader(final ObjectName name) {
--- a/src/java.management/share/classes/com/sun/jmx/util/Modules.java	Sat Jul 11 07:50:56 2015 +0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.sun.jmx.util;
-
-import javax.management.ObjectName;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.lang.reflect.Module;
-
-public final class Modules {
-    private Modules() { }
-
-    /**
-     * Ensures that module java.management reads the given module.
-     */
-    public static void ensureReadable(Module targetModule) {
-        Module module = ObjectName.class.getModule();
-        if (module.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { module.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
-}
--- a/src/java.management/share/classes/javax/management/MBeanServerFactory.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.management/share/classes/javax/management/MBeanServerFactory.java	Sat Jul 11 09:39:22 2015 +0100
@@ -26,7 +26,6 @@
 package javax.management;
 
 import com.sun.jmx.defaults.JmxProperties;
-import com.sun.jmx.util.Modules;
 import static com.sun.jmx.defaults.JmxProperties.JMX_INITIAL_BUILDER;
 import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
 import com.sun.jmx.mbeanserver.GetPropertyAction;
@@ -458,7 +457,7 @@
      * a JMRuntimeException.
      **/
     private static MBeanServerBuilder newBuilder(Class<?> builderClass) {
-        Modules.ensureReadable(builderClass.getModule());
+        MBeanServerFactory.class.getModule().addReads(builderClass.getModule());
         try {
             final Object abuilder = builderClass.newInstance();
             return (MBeanServerBuilder)abuilder;
--- a/src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java	Sat Jul 11 09:39:22 2015 +0100
@@ -37,7 +37,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import com.sun.jmx.util.Modules;
 import com.sun.jmx.remote.util.ClassLogger;
 import com.sun.jmx.remote.util.EnvHelp;
 import sun.reflect.misc.ReflectUtil;
@@ -533,7 +532,7 @@
 
             // We have just proved that this cast is correct
             Class<? extends T> providerClassT = Util.cast(providerClass);
-            Modules.ensureReadable(providerClass.getModule());
+            JMXConnectorFactory.class.getModule().addReads(providerClass.getModule());
             try {
                 return providerClassT.newInstance();
             } catch (Exception e) {
--- a/src/java.management/share/classes/sun/management/MappedMXBeanType.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.management/share/classes/sun/management/MappedMXBeanType.java	Sat Jul 11 09:39:22 2015 +0100
@@ -40,7 +40,6 @@
 import java.security.PrivilegedExceptionAction;
 import javax.management.openmbean.*;
 import static javax.management.openmbean.SimpleType.*;
-import com.sun.jmx.util.Modules;
 
 /**
  * A mapped mxbean type maps a Java type to an open type.
@@ -704,7 +703,7 @@
                         types.toArray(new OpenType<?>[0]));
             }
 
-            Modules.ensureReadable(c.getModule());
+            MappedMXBeanType.class.getModule().addReads(c.getModule());
         }
 
         Type getJavaType() {
--- a/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java	Sat Jul 11 09:39:22 2015 +0100
@@ -34,8 +34,6 @@
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import javax.net.ssl.SSLSocket;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 
 import javax.naming.CommunicationException;
 import javax.naming.ServiceUnavailableException;
@@ -268,11 +266,7 @@
 
             Module thisModule = Connection.class.getModule();
             Module targetModule = socketFactoryClass.getModule();
-            if (!thisModule.canRead(targetModule)) {
-                PrivilegedAction<Void> pa
-                    = () -> { thisModule.addReads(targetModule); return null; };
-                AccessController.doPrivileged(pa);
-            }
+            thisModule.addReads(targetModule);
 
             SocketFactory factory = (SocketFactory) getDefault.invoke(null, new Object[]{});
 
--- a/src/java.naming/share/classes/javax/naming/spi/NamingManager.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.naming/share/classes/javax/naming/spi/NamingManager.java	Sat Jul 11 09:39:22 2015 +0100
@@ -25,8 +25,6 @@
 
 package javax.naming.spi;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.lang.reflect.Module;
 import java.net.MalformedURLException;
 import java.util.*;
@@ -918,8 +916,6 @@
 
     private static void ensureReadable(Module targetModule) {
         Module thisModule = NamingManager.class.getModule();
-        PrivilegedAction<Void> pa =
-             () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
+        thisModule.addReads(targetModule);
     }
 }
--- a/src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java	Sat Jul 11 09:39:22 2015 +0100
@@ -26,8 +26,6 @@
 package com.sun.rowset;
 
 import java.lang.reflect.Module;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.sql.*;
 import javax.sql.*;
 import java.io.*;
@@ -2983,12 +2981,7 @@
     }
 
     private static void ensureReadable(Module targetModule) {
-        Module thisModule = CachedRowSetImpl.class.getModule();
-        if (thisModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
+        CachedRowSetImpl.class.getModule().addReads(targetModule);
     }
 
     /**
--- a/src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java	Sat Jul 11 09:39:22 2015 +0100
@@ -32,9 +32,6 @@
 import sun.reflect.misc.ReflectUtil;
 
 import com.sun.rowset.*;
-import java.lang.reflect.Module;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.text.MessageFormat;
 import javax.sql.rowset.*;
 import javax.sql.rowset.serial.SQLInputImpl;
@@ -577,7 +574,7 @@
                         SQLData obj = null;
                         try {
                             ReflectUtil.checkPackageAccess(c);
-                            ensureReadable(c.getModule());
+                            CachedRowSetImpl.class.getModule().addReads(c.getModule());
                             obj = (SQLData)c.newInstance();
                         } catch (Exception ex) {
                             throw new SQLException("Unable to Instantiate: ", ex);
@@ -1473,13 +1470,4 @@
         return isValid;
     }
 
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = CachedRowSetImpl.class.getModule();
-        if (thisModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
-
 }
--- a/src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java	Sat Jul 11 09:39:22 2015 +0100
@@ -25,7 +25,6 @@
 
 package javax.sql.rowset;
 
-import java.lang.reflect.Module;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.sql.SQLException;
@@ -275,19 +274,10 @@
         }
 
         ReflectUtil.checkPackageAccess(factoryClass);
-        ensureReadable(factoryClass.getModule());
+        RowSetProvider.class.getModule().addReads(factoryClass.getModule());
         return factoryClass;
     }
 
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = RowSetProvider.class.getModule();
-        if (thisModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
-
     /**
      * Use the ServiceLoader mechanism to load  the default RowSetFactory
      * @return default RowSetFactory Implementation
--- a/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Sat Jul 11 07:50:56 2015 +0800
+++ b/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Sat Jul 11 09:39:22 2015 +0100
@@ -24,9 +24,6 @@
  */
 package javax.sql.rowset.serial;
 
-import java.lang.reflect.Module;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.sql.*;
 import java.util.Arrays;
 import java.util.Map;
@@ -481,7 +478,7 @@
                 SQLData obj = null;
                 try {
                     ReflectUtil.checkPackageAccess(c);
-                    ensureReadable(c.getModule());
+                    SQLInputImpl.class.getModule().addReads(c.getModule());
                     obj = (SQLData)c.newInstance();
                 } catch (Exception ex) {
                     throw new SQLException("Unable to Instantiate: ", ex);
@@ -498,15 +495,6 @@
         return attrib;
     }
 
-    private static void ensureReadable(Module targetModule) {
-        Module thisModule = SQLInputImpl.class.getModule();
-        if (thisModule.canRead(targetModule))
-            return;
-        PrivilegedAction<Void> pa =
-            () -> { thisModule.addReads(targetModule); return null; };
-        AccessController.doPrivileged(pa);
-    }
-
     /**
      * Retrieves the value at the head of this <code>SQLInputImpl</code> object
      * as a <code>Ref</code> object in the Java programming language.