glassfish
  1. glassfish
  2. GLASSFISH-20776

when new InitialContext ,the java.lang.NullPointerException is happenning

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0_dev
    • Fix Version/s: None
    • Component/s: orb
    • Labels:
      None
    • Environment:

      windows

      Description

      when execute the following code

      Properties props = new Properties();
      props.setProperty("com.sun.appserv.iiop.loadbalancingpolicy","ic-based");
      props.setProperty(ORBLocator.OMG_ORB_INIT_HOST_PROPERTY,
      "10.167.234.33");
      props.setProperty(ORBLocator.OMG_ORB_INIT_PORT_PROPERTY,
      "23700");
      InitialContext ic = new InitialContext(props);
      

      the following Exception is happenning

      Exception in thread "main" java.lang.NullPointerException
      	at org.glassfish.enterprise.iiop.impl.NamingClusterInfoImpl.getEndpointList(NamingClusterInfoImpl.java:173)
      	at org.glassfish.enterprise.iiop.impl.NamingClusterInfoImpl.initGroupInfoService(NamingClusterInfoImpl.java:99)
      	at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:168)
      	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
      	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
      	at javax.naming.InitialContext.init(InitialContext.java:242)
      	at javax.naming.InitialContext.<init>(InitialContext.java:216)
      	at Main.main(Main.java:22)
      

        Activity

        Hide
        lzg5039 added a comment -

        it is a style or it is a bug?

        Show
        lzg5039 added a comment - it is a style or it is a bug?
        Hide
        lzg5039 added a comment -

        In method of initGroupInfoService get IP firstly,then initialize rrPolicy .But the metod of getEndpointList uses the rrPolicy which does not be initialized.

        method:initGroupInfoService
        final List<String> epList = getEndpointList(myEnv, defaultHost, defaultPort);
        rrPolicy = new RoundRobinPolicy(epList);
        
        method:getEndpointList
        if (list.isEmpty()) {
            final String urlValue = (String)env.get(
                    ORBLocator.JNDI_PROVIDER_URL_PROPERTY) ;
            list.addAll( rrPolicy.getEndpointForProviderURL( urlValue ) ) ;
        }
        
        if (list.isEmpty()) {
            String host = getEnvSysProperty( env,
                    ORBLocator.OMG_ORB_INIT_HOST_PROPERTY) ;
            String port = getEnvSysProperty( env,
                    ORBLocator.OMG_ORB_INIT_PORT_PROPERTY) ;
        
             if (host != null && port != null) {
                list.addAll(rrPolicy.getAddressPortList(host, port) ) ;
                logger.log(Level.WARNING, NO_ENDPOINT_SELECTED, new Object[]{host, port});
            }
        }
        
        Show
        lzg5039 added a comment - In method of initGroupInfoService get IP firstly,then initialize rrPolicy .But the metod of getEndpointList uses the rrPolicy which does not be initialized. method:initGroupInfoService final List<String> epList = getEndpointList(myEnv, defaultHost, defaultPort); rrPolicy = new RoundRobinPolicy(epList); method:getEndpointList if (list.isEmpty()) { final String urlValue = (String)env.get( ORBLocator.JNDI_PROVIDER_URL_PROPERTY) ; list.addAll( rrPolicy.getEndpointForProviderURL( urlValue ) ) ; } if (list.isEmpty()) { String host = getEnvSysProperty( env, ORBLocator.OMG_ORB_INIT_HOST_PROPERTY) ; String port = getEnvSysProperty( env, ORBLocator.OMG_ORB_INIT_PORT_PROPERTY) ; if (host != null && port != null) { list.addAll(rrPolicy.getAddressPortList(host, port) ) ; logger.log(Level.WARNING, NO_ENDPOINT_SELECTED, new Object[]{host, port}); } }
        Hide
        lzg5039 added a comment -

        please help me to review the following modified

        method:getEndpointList
        if (list.isEmpty()) {
            final String urlValue = (String)env.get(
                    ORBLocator.JNDI_PROVIDER_URL_PROPERTY) ;
        +    if(rrPolicy != null){
                list.addAll( rrPolicy.getEndpointForProviderURL( urlValue ) ) ;
        +    } else {
        +        if (urlValue != null) {
        +           try {
        +                IiopUrl providerURL = new IiopUrl(urlValue);
        +                IiopUrl.Address iiopUrlAddress = 
        +                    (IiopUrl.Address)(providerURL.getAddresses().elementAt(0));
        +                String host = iiopUrlAddress.host;
        +                int portNumber = iiopUrlAddress.port;
        +                String port = Integer.toString(portNumber);
        +                list.add(host + ":" + port);
        +            } catch (MalformedURLException me) {
        +                logger.log(Level.WARNING, RoundRobinPolicy.PROVIDER_EXCEPTION, new Object[]{me, urlValue});
        +            }
        +        }
        +    }
        }
        
        if (list.isEmpty()) {
            String host = getEnvSysProperty( env,
                    ORBLocator.OMG_ORB_INIT_HOST_PROPERTY) ;
            String port = getEnvSysProperty( env,
                    ORBLocator.OMG_ORB_INIT_PORT_PROPERTY) ;
        
             if (host != null && port != null) {
        +        if(rrPolicy != null){
                    list.addAll(rrPolicy.getAddressPortList(host, port) ) ;
                    logger.log(Level.WARNING, NO_ENDPOINT_SELECTED, new Object[]{host, port});
        +        } else {
        +            list.add(host + ":" + port);
        +        }    
        +     }
        }
        
        
        Show
        lzg5039 added a comment - please help me to review the following modified method:getEndpointList if (list.isEmpty()) { final String urlValue = (String)env.get( ORBLocator.JNDI_PROVIDER_URL_PROPERTY) ; + if(rrPolicy != null){ list.addAll( rrPolicy.getEndpointForProviderURL( urlValue ) ) ; + } else { + if (urlValue != null) { + try { + IiopUrl providerURL = new IiopUrl(urlValue); + IiopUrl.Address iiopUrlAddress = + (IiopUrl.Address)(providerURL.getAddresses().elementAt(0)); + String host = iiopUrlAddress.host; + int portNumber = iiopUrlAddress.port; + String port = Integer.toString(portNumber); + list.add(host + ":" + port); + } catch (MalformedURLException me) { + logger.log(Level.WARNING, RoundRobinPolicy.PROVIDER_EXCEPTION, new Object[]{me, urlValue}); + } + } + } } if (list.isEmpty()) { String host = getEnvSysProperty( env, ORBLocator.OMG_ORB_INIT_HOST_PROPERTY) ; String port = getEnvSysProperty( env, ORBLocator.OMG_ORB_INIT_PORT_PROPERTY) ; if (host != null && port != null) { + if(rrPolicy != null){ list.addAll(rrPolicy.getAddressPortList(host, port) ) ; logger.log(Level.WARNING, NO_ENDPOINT_SELECTED, new Object[]{host, port}); + } else { + list.add(host + ":" + port); + } + } }

          People

          • Assignee:
            Harshad Vilekar
            Reporter:
            lzg5039
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: