java - NPE when obtaining KeyStore instance -


i have simple code working while back. trying keystore instance can use enable ssl. problem null pointer exception below , can't seem find solution anywhere. use openjdk 8 on ubuntu 15.04 32 bit.

//do other initializations things ... keystore ks = keystore.getinstance("pkcs12"); keystore ts = keystore.getinstance("pkcs12");  char[] keymanagerpassphrase = keymanagerpassphrasestring.tochararray(); char[] keystorepassphrase = keystorepassphrasestring.tochararray(); char[] truststorepassphrase = truststorepassphrasestring.tochararray();  ks.load(new fileinputstream(keystorefile), keystorepassphrase);  keymanagerfactory kmf = keymanagerfactory.getinstance("sunx509"); kmf.init(ks, keymanagerpassphrase);  trustmanager[] trustmanagers = null;     if( usecustomtruststore ) {          ts.load(new fileinputstream(truststorefile), truststorepassphrase);           trustmanagerfactory tmf = trustmanagerfactory.getinstance("sunx509");             tmf.init(ts);           trustmanagers = tmf.gettrustmanagers();         }         sslcontext sslcontext = sslcontext.getinstance(protocal);          sslcontext.init(kmf.getkeymanagers(), trustmanagers , null);          return sslcontext.createsslengine(); 

the exception thrown is:

caused by: java.lang.nullpointerexception @ java.security.provider$servicekey.<init>(provider.java:872) @ java.security.provider$servicekey.<init>(provider.java:865) @ java.security.provider.getservice(provider.java:1039) @ sun.security.jca.providerlist.getservice(providerlist.java:332) @ sun.security.jca.getinstance.getinstance(getinstance.java:157) @ java.security.security.getimpl(security.java:695) @ java.security.keystore.getinstance(keystore.java:848) 

how can proceed?

this q's little old near top of google results problem, i'll try help.

to debug npe in java's codebase, need make sure have java source code available in ide; can check hint on null. seem using jdk 8, it's line:

algorithm = algorithm.touppercase(english); 

plus, there's nothing else in servicekey init method (constructor) cause npe. so... string algorithm parameter come from, passed constructor?

it looks it's passed through of these layers; see at java.security.security.getimpl(security.java:695) -- algorithm first param passed in there.

unwrap 1 more: at java.security.keystore.getinstance(keystore.java:848) -- param pass in here called "type", that's what's passed security.getimpl algorithm.

so bug you're passing null type param when call keystore.getinstance(). doesn't seem match source code listed, may not have compiled code properly. add in "sanity check" -- e.g., println earlier in code; , see line number in your code indicated further down stack trace.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -