Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8048091 JNDI code cleanup and modernization
  3. JDK-8048175

Remove redundant use of reflection on core classes from JNDI

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                prappo Pavel Rappo
                Reporter:
                chegar Chris Hegarty
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: