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

ExceptionInInitializerError in Keycloak: error found in ResourceLoader #79

Closed
MoreDreadd opened this issue Jan 18, 2021 · 7 comments
Closed

Comments

@MoreDreadd
Copy link

MoreDreadd commented Jan 18, 2021

Hi team,

I wanted to use this library to create a Keycloak extension checking for the strength of the password.
But everytime I tried calling the zxcvbn.measure() method, I got a java.lang.ExceptionInInitializerError.

Uncaught server error: java.lang.ExceptionInInitializerError
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.Matching.<clinit>(Matching.java:18)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.Zxcvbn.createMatching(Zxcvbn.java:45)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.Zxcvbn.measure(Zxcvbn.java:32)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.Zxcvbn.measure(Zxcvbn.java:15)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//keycloak.passwordstrength.PasswordStrengthProvider.validate(PasswordStrengthProvider.java:31)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//keycloak.passwordstrength.PasswordStrengthProvider.validate(PasswordStrengthProvider.java:26)

[...]

Caused by: java.lang.NullPointerException
	at java.base/java.io.Reader.<init>(Reader.java:167)
	at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:109)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.matchers.Dictionary.read(Dictionary.java:40)
	at deployment.keycloak-extensions-bundle-11.0.0-SNAPSHOT.ear.keycloak-keycloak-extensions-password-strength-11.0.0-SNAPSHOT.jar//com.nulabinc.zxcvbn.matchers.Dictionary.<clinit>(Dictionary.java:25)
        ... 105 more

After debugging I was able to locate the error: in matchers/ResourceLoader.java in line 8, you are using Thread.currentThread().getContextClassLoader().getResourceAsStream(path) to get the files from the resources folder. As it turned out, this is null when using Keycloak.
But: using getClass ().getClassLoader ().getResourceAsStream (path) works great!

Is there a reason you are using the Thread-version here? Otherwise it might be nice to replace this line with the Class-version to ensure compatibility with software like Keycloak (I don't know if this problem also appears with other projects).

@vvatanabe
Copy link
Member

@MoreDreadd
We are currently investigating. There was a similar bug report below.
#66

Are you also using Android with zxcvbn4j?

@MoreDreadd
Copy link
Author

@vvatanabe no, I am running the program on Windows 10

@vvatanabe
Copy link
Member

@MoreDreadd
In matchers/ResourceLoader.java on line 8, the result of Thread.currentThread().getContextClassLoader().getResourceAsStream(path) is null, right?

In this case, ClassLoader.getSystemResourceAsStream(path) in the 12th line is executed, is it also null?

vvatanabe added a commit that referenced this issue Jan 19, 2021
vvatanabe added a commit that referenced this issue Jan 19, 2021
Fix a ExceptionInInitializerError in Keycloak: error found in ResourceLoader #79
@vvatanabe
Copy link
Member

@MoreDreadd I fixed it and released 1.3.2. Please check it!

@MoreDreadd
Copy link
Author

@vvatanabe I just checked and unfortunately it still doesn't work.
I have to correct my report from above: not the result of Thread.currentThread().getContextClassLoader().getResourceAsStream(path) is null, but the result of RESOURCE_LOADER.getInputStream(buildResourcePath(filename)) in line 45 in Dictionary which is why the fallback cases don't work.

@vvatanabe
Copy link
Member

vvatanabe commented Jan 20, 2021

@MoreDreadd
Thanks for reporting. We will continue to investigate. Could you please provide the following information?

  • OS details
  • Java version
  • Java Framework (eg. spring-boot)
  • Are you running it on WSL or Docker for Windows?
  • Stack trace when an error occurs

vvatanabe added a commit that referenced this issue Jan 22, 2021
fallback in the process of getting the resource as a stream (#79)
@vvatanabe
Copy link
Member

@MoreDreadd I released 1.3.3 include #81. Please check it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants