JDK-8048175 : Remove redundant use of reflection on core classes from JNDI
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-06-26
  • Updated: 2024-03-11
  • Resolved: 2014-07-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b24Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
There are many places in the JNDI implementation that use reflection to access core classes and methods. These seem to date back to a time when JNDI was a separate bundle, and when some of these classes/methods were recently added to the platform. This is no longer the case, and the code can be simplified greatly by removing these usages of reflection, and replacing them with static references.

Just two examples are included here to give some context:

com/sun/jndi/ldap/ClientId.java

    ClientId(int version, String hostname, int port, String protocol,
                 Control[] bindCtls, OutputStream trace, String socketFactory) {
        ....
        Class<?> objClass = Class.forName("java.lang.Object");
        ....

This can of course be replaced with java.lang.Object.class!
---

com/sun/jndi/ldap/Connection.java

     private Object createInetSocketAddress(String host, int port)
            throws NoSuchMethodException {

        try {
            Class<?> inetSocketAddressClass =
                Class.forName("java.net.InetSocketAddress");

            Constructor<?> inetSocketAddressCons =
                inetSocketAddressClass.getConstructor(new Class<?>[]{
                String.class, int.class});

            return inetSocketAddressCons.newInstance(new Object[]{
                host, new Integer(port)});

        } catch (ClassNotFoundException |
                 InstantiationException |
                 InvocationTargetException |
                 IllegalAccessException e) {
            throw new NoSuchMethodException();

        }
    }

java.net.SocketAddress is a core class.
Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/667926cb70ff User: lana Date: 2014-07-18 15:31:11 +0000
18-07-2014

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/667926cb70ff User: prappo Date: 2014-07-15 15:47:24 +0000
15-07-2014