nullpointerexception - Jasypt fails to initialize on Android 5.1.1 and above, ClassLoader is null -


i using jasypt (compile 'org.jasypt:jasypt:1.9.2') standard pbe encryptor

    standardpbebyteencryptor strongbinaryencryptor = new standardpbebyteencryptor();     strongbinaryencryptor.setalgorithm("...");     strongbinaryencryptor.setkeyobtentioniterations(...);     strongbinaryencryptor.setprovidername(bouncycastleprovider.provider_name);     strongbinaryencryptor.setpassword("...");     byte[] encryptedbytes = strongbinaryencryptor.encrypt(bytes); 

and used work without problem, crashes following root exception:

e/androidruntime:  caused by: java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.class java.lang.classloader.loadclass(java.lang.string)' on null object reference e/androidruntime:     @ org.jasypt.normalization.normalizer.initializeicu4j(normalizer.java:139) e/androidruntime:     @ org.jasypt.normalization.normalizer.normalizetonfc(normalizer.java:96) e/androidruntime:     @ org.jasypt.encryption.pbe.standardpbebyteencryptor.initialize(standardpbebyteencryptor.java:661) e/androidruntime:     @ org.jasypt.encryption.pbe.standardpbebyteencryptor.encrypt(standardpbebyteencryptor.java:873)  

the same code works on kitkat phone , lollipop emulator, example crashes on oneplusone.

if @ source, see this:

static void initializeicu4j() throws classnotfoundexception {             thread.currentthread().getcontextclassloader().loadclass(icu_normalizer_class_name);     useicunormalizer = boolean.true; } 

which means thread.currentthread().getcontextclassloader() null. didn't use happen, , don't know caused change in behavior. not sure should fix it.

any ideas?

based on wiki page has since been removed google code, used bug in dalvik well, patch commited in froyo. however, art seems have resurfaced exact same problem.

apparently per https://web.archive.org/web/20120303234738/http://code.google.com/p/dalvik/wiki/javaxpackages solution initialize class loader manually in activity.oncreate().

public class hellostax extends activity {   @override public void oncreate(bundle savedinstancestate) {      ...      /*      * ensure factory implementation loaded application      * classpath (which contains implementation classes), rather      * system classpath (which doesn't).      */     thread.currentthread().setcontextclassloader(getclass().getclassloader());      ...   } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -