Sun.security cannot be found after upgrading Java
Asked Answered
E

1

3

I have an application created with Play 2.0. I implemented scribe-java library to use some OAuth services. Until today everything was fine but when I upgrade jdk and reboot the server I couldn't use scribe-java library. It seems it uses some classes like sun/security/pkcs11/P11Key and sun/security/pkcs11/Length in sun.security package but couldn't find it.

"java -version" returns this:

java version "1.7.0_03"

OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)

OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)

Play 2.0 stacktrace:

! @6bk5o8md2 - Internal server error, for request [GET /user/service/google/oauth_callback/?code=[SECRET]] ->

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NoClassDefFoundError: sun/security/pkcs11/P11Key]]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.2]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.2]
        at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
        at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.2]
        at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: java.lang.NoClassDefFoundError: sun/security/pkcs11/P11Key
        at sun.security.pkcs11.P11ECKeyFactory.generatePublic(P11ECKeyFactory.java:234) ~[sunpkcs11.jar:na]
        at sun.security.pkcs11.P11ECKeyFactory.implTranslatePublicKey(P11ECKeyFactory.java:103) ~[sunpkcs11.jar:na]
        at sun.security.pkcs11.P11ECKeyFactory.engineGeneratePublic(P11ECKeyFactory.java:152) ~[sunpkcs11.jar:na]
        at java.security.KeyFactory.generatePublic(KeyFactory.java:334) ~[na:1.7.0_03]
        at sun.security.x509.X509Key.buildX509Key(X509Key.java:223) ~[na:1.7.0_03]
        at sun.security.x509.X509Key.parse(X509Key.java:170) ~[na:1.7.0_03]
Expeller answered 13/9, 2012 at 18:47 Comment(5)
Play 2.0 runs java with $JAVA_HOME path or standart java command so if I can't fix the problem I will try to download another jdk version and define another jdk directory by defining $JAVA_HOME. However I'm looking for a solution that fixes the problem in system jdk.Expeller
Unfortunately, you probably won't find one. Using classes from the sun packages is a pretty dirty practice in Java, and the only solution if one of your libraries is using them besides using the old JDK is to hope that an updated version of the library will be released soon that fixes the problem. See this FAQ question on Oracle's site.Haunch
However I don't think that sun.security package is not available in newest release of jdk (it's because), isn't that possible that my environment has a problem?Expeller
That's true, but sun.security.pkcs11 isn't. I took a look in my rt.jar file on my local machine here, and I went to sun.security and the pkcs11 package no longer exists.Haunch
That's also true for my local environment (not server) but instead of pkcs11, there is pkcs12 package. The reason that I said sun.security package is not available in my server is when I import sun.security.* it throws package sun.security does not exist.Expeller
E
2

After another update && upgrade, jdk upgraded from 2.1.1pre to 2.3.2 and the problem fixed. What happened is that Oracle wasted my 2 hours, sucks. :(

Expeller answered 13/9, 2012 at 21:9 Comment(2)
Glad to hear you fixed it! Don't forget to accept your answer so this is marked as 'resolved'Balm
Thanks @PabloFernandez! Stackoverflow does not allow me to accept my answer first 2 days. Small note: The reason that I tagged Scribe in this question and posted Github issues is that some Scribe users might seen this error before me. :)Expeller

© 2022 - 2024 — McMap. All rights reserved.