Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DnsContextFactory not accessible in java 17 #25210

Closed
dominikrebhan opened this issue May 5, 2023 · 8 comments · Fixed by #25314
Closed

DnsContextFactory not accessible in java 17 #25210

dominikrebhan opened this issue May 5, 2023 · 8 comments · Fixed by #25314
Assignees
Labels
Needs member attention release bug This bug is present in a released version of Open Liberty release:23006

Comments

@dominikrebhan
Copy link

Describe the bug
With Java 17 and Liberty trying to make a dns lookup fails. A ffdc is created with this message:

Exception = java.lang.IllegalAccessException
Source = com.ibm.ws.jndi.internal.WASURLObjectFactoryFinder
probeid = 81
Stack Dump = java.lang.IllegalAccessException: class com.ibm.ws.jndi.internal.WASURLObjectFactoryFinder cannot access class com.sun.jndi.url.dns.dnsURLContextFactory (in module jdk.naming.dns) because module jdk.naming.dns does not export com.sun.jndi.url.dns to unnamed module @188cf1f7

Steps to Reproduce

Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
env.put(Context.PROVIDER_URL, "dns:");
dirContext = new InitialDirContext(env);
 
Attributes attrs = dirContext.getAttributes("dns:/...");

Expected behavior
Successful dns lookup

Diagnostic information:

  • OpenLiberty Version: 23.0.0.3
  • Java Version: Java 17

Additional context
I think it is necessary to add this to the java9.options starting with java 17. This resolves my problem:

--add-exports
jdk.naming.dns/com.sun.jndi.url.dns=ALL-UNNAMED

https://github.com/OpenLiberty/open-liberty/blob/integration/dev/com.ibm.ws.kernel.boot/publish/platform/java/java9.options

@dominikrebhan dominikrebhan added the release bug This bug is present in a released version of Open Liberty label May 5, 2023
@jhanders34
Copy link
Member

#22360 was supposed to help this, but maybe the package name was wrong or it has changed.

@gjwatts gjwatts self-assigned this May 5, 2023
@dominikrebhan
Copy link
Author

Unfortunately this didn't help. I think it is because the namespace is different:

com.sun.jndi.dns vs. com.sun.jndi.url.dns

@gjwatts
Copy link
Member

gjwatts commented May 17, 2023

Sorry, I will start working on this.

@gjwatts
Copy link
Member

gjwatts commented May 19, 2023

Hi @dominikrebhan. To help with this recreate, can you please give me a specific example of an attribute name I can use in this line?
Attributes attrs = dirContext.getAttributes("dns:/...");

@dominikrebhan
Copy link
Author

dominikrebhan commented May 19, 2023

You can simply use any address. It won't go any further, it creates immediately the ffdc:

public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
    try {
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
        env.put(Context.PROVIDER_URL, "dns:");
        var dirContext = new InitialDirContext(env);

        var attrs = dirContext.getAttributes("dns:/www.github.com");
        System.out.println(attrs);
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }
}

I tried this with the vanilla zip from the download page on a fresh windows vm. I just had to copy the java9.options to my local server jvm.options, because it seems this isn't loaded either. But this may be another issue or just some local error. It happened on macOS as well, but I think the DNS-issue is more relevant.

messages.log
ffdc.log

@gjwatts
Copy link
Member

gjwatts commented May 22, 2023

@dominikrebhan Thanks for sending the messages.log file, that helped. I was getting the same DNS error and thought I was doing something wrong.
javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name 'dns:/www.github.com'

However, I don't get the java.lang.IllegalAccessException exception in my log file, nor do I get an FFDC file created when I run it.

Looking at your messages.log file, I am guessing in your server.xml file for features you have something like:

    <featureManager>
        <feature>webProfile-10.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

In mine, I have:

    <featureManager>
        <feature>servlet-6.0</feature>
	<feature>localConnector-1.0</feature>
    </featureManager>

But when I switch to use the webProfile-10.0 feature (which pulls in the servlet-6.0 feature), then I get the same illegalAccessException that you do.

@gjwatts
Copy link
Member

gjwatts commented May 23, 2023

@dominikrebhan never mind, Jared figured out I was missing the jndi-1.0 feature that webProfile-10.0 pulls in. Once I include that in my server.xml

<featureManager>
	<feature>servlet-6.0</feature>
	<feature>jndi-1.0</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

Then I get the same illegalAccessException you reported. I am working on adding the correct entry into the java9.options file and adding a test for this into one of our FAT buckets.

Thank you for taking your time to report this to us so we can make Open Liberty even better!

@gjwatts
Copy link
Member

gjwatts commented Jun 6, 2023

@dominikrebhan I have merged the PR to get this fixed. I expect it to be in our next release. Thanks again for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs member attention release bug This bug is present in a released version of Open Liberty release:23006
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants