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

static block in Password class does not initialize due to NPE #120

Closed
divijen opened this issue Jul 26, 2023 · 3 comments
Closed

static block in Password class does not initialize due to NPE #120

divijen opened this issue Jul 26, 2023 · 3 comments
Labels
Milestone

Comments

@divijen
Copy link

divijen commented Jul 26, 2023

Issue Description:
Application throws a NoClassDefFoundError for Password class even though it is present in the final application build.

Steps to reproduce:
Simply use the Password class to create an scrypt hash as mentioned in the password4j getstarted page.

Expected behavior:
Generate a hash without Exception.

Environment:

  • OS: mxlinux
  • JDK Amazon Corretto
  • Version 8
  • enterprise ear file deployed on wildfly server

Additional context:
This is happening because the static block of Password.java is not loading due to an eventual NPE that occurs in the library code. This in turn stops this class from loading and manifests as a java.lang.NoClassDefFoundError in the application.

Please confirm if this is an issue or requires any configuration change.

Exception stack trace:
Caused by: java.lang.NullPointerException
at com.password4j.AlgorithmFinder.getAllPBKDF2Variants(AlgorithmFinder.java:346)
at com.password4j.Utils.printBanner(Utils.java:582)
at com.password4j.Password.(Password.java:37)

Problem in line number 346 of AlgorithmFinder class. The provider creating the problem is ThreadLocalSecurityProvider. The size says 4 but returns null.
image
image

@firaja
Copy link
Member

firaja commented Jul 27, 2023

Hi @divijen,

thank you for opening the issue.
This is caused by your JVM that has a provider containing no services.

Can you post the result of this in your environment? Thank you

        for (Provider provider : Security.getProviders())
        {
            System.out.println(provider.getName());
            if (provider.getServices() != null)
            {
                for (Provider.Service service : provider.getServices())
                {
                    System.out.println(" - " + service.getAlgorithm());
                }
            }

        }

@firaja firaja added this to the 1.7.2 milestone Jul 31, 2023
@divijen
Copy link
Author

divijen commented Jul 31, 2023

Thank you @firaja

I could probably write a small chunk where there might be an issue:

XMLDSig
 - http://www.w3.org/2006/12/xml-c14n11#WithComments
 - http://www.w3.org/2000/09/xmldsig#base64
 - http://www.w3.org/TR/1999/REC-xslt-19991116
 - http://www.w3.org/2001/10/xml-exc-c14n#
 - http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments
 - http://www.w3.org/2000/09/xmldsig#enveloped-signature
 - http://www.w3.org/2002/06/xmldsig-filter2
 - DOM
 - http://www.w3.org/TR/2001/REC-xml-c14n-20010315
 - http://www.w3.org/2001/10/xml-exc-c14n#WithComments
 - http://www.w3.org/2006/12/xml-c14n11
 - http://www.w3.org/TR/1999/REC-xpath-19991116
 - DOM
TLSP
SunPCSC
 - PC/SC

firaja added a commit that referenced this issue Aug 20, 2023
@firaja
Copy link
Member

firaja commented Aug 21, 2023

Hi @divijen a fix is published for this problem.
You can try version 1.7.2 and see if it's solved.

What I found weird is that with Amazon Corretto 1.8 I never get a null from provider.getServices(), even if the Provider has no Service.
The only way to replicate it was to override method Provider#getServices() and force it to return null. Maybe you have a library doing so.

@firaja firaja moved this to Done in Core development Aug 21, 2023
@firaja firaja closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

2 participants