Menu

#62 Null pointer while registering NameService

None
closed
nobody
None
5
2019-05-18
2018-02-20
oshoukry
No

In the file: DNSJavaNameServiceDescriptor
There is a static block which attempts to get the ClassLoader using NameService.class.getClassLoader().
If NameService is loaded by the BootLoader (in my case), null is returned, causing the Proxy.newProxyInstance call to fail on the following line.

Suggestion to change code from:

  ClassLoader loader = NameService.class.getClassLoader();
  nameService = (NameService) Proxy.newProxyInstance(loader,
      new Class[] { NameService.class },
      new DNSJavaNameService());

To:

    ClassLoader loader = NameService.class.getClassLoader();
    if (loader == null) {
        loader = ClassLoader.getSystemClassLoader();
    }
    nameService = (NameService) Proxy.newProxyInstance(loader,
            new Class[] { NameService.class },
            new DNSJavaNameService());

Discussion

  • Ingo

    Ingo - 2019-05-18
    • status: open --> closed
    • Group: -->
     
  • Ingo

    Ingo - 2019-05-18
     
MongoDB Logo MongoDB