• Post Reply Bookmark Topic Watch Topic
  • New Topic

org.apache.commons.codec.binary.Base64.decodeBase64

 
Abhishek Rath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

We are getting the error when we are pointing to JDK 8 however when we change this to JDK 7 it got resolved. In the POM we have the below entry

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.codec</artifactId>
</dependency>

The exception stack trace is

java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64(Ljava/lang/String;)[B at


Could you please suggest if Codec is somehow related to JDK version?

Regards
Abhishek
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly, no. That class will be in some jar file which is independent of the JRE.

However... there's a folder associated with the JRE called "Installed Extensions". If you put a jar file into this folder then it's automatically considered by the JRE to be part of the classpath any time you run a class. This can be very convenient, except that when you upgrade to a new JRE you may have forgotten you put that jar in the Installed Extensions folder of the old JRE, or you may not have known that somebody else in your organization did that. And since the jar isn't in the Installed Extensions folder of the new JRE, suddenly things don't work right any more.

This may be what's happening to you.

Tutorial here: Installed Extensions.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Rath wrote:<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.codec</artifactId>
</dependency>

You are you using an obscure version of Apache Commons Codec? The official Maven dependency uses groupId commons-codec and artifactId commons-codec. But for Base64 you don't need it at all anymore; just use java.util.Base64 instead.
 
Abhishek Rath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does JDK 7 and JDK 8 works differently when it comes to loading a class loading. What I found is that in my Lib I have both commons-codec-1.2.jar and com.springsource.org.apache.commons.codec-1.5.0.jar . However my application is working fine in JDK 7 however complaining in JDK 8 with a no such method error.


The decodeBase64(String) is added in codec 1.4 onwards. So wanted to know if the class loading pattern is different in JDK 7 and 8.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Rath wrote:Does JDK 7 and JDK 8 works differently when it comes to loading a class loading.


Not that I know of.

What I found is that in my Lib I have both commons-codec-1.2.jar and com.springsource.org.apache.commons.codec-1.5.0.jar .


Your "Lib"? What's that?
 
Abhishek Rath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lib means WEB-INF/lib folder which is having all the Jar files.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you're talking about a web application? Parts of your original question suggest that you're talking about Maven. Perhaps it would help if you explained what context "getting" the error actually refers to. Stack trace etc would be helpful.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Rath wrote:Does JDK 7 and JDK 8 works differently when it comes to loading a class loading.

Yes. I don't know the specifics, but when we upgraded from Java 7 to 8 at work we had to include an extra (provided) dependency (JBoss msc), otherwise Maven wouldn't even build the project.

But why not just upgrade your commons-codec-1.2.jar to a newer version (1.10 is already out), or (if you only use Base64 functionality) drop it altogether in favour of java.util.Base64?
And the nice part: all of the static methods in Base64 that return a Decoder or Encoder and take no arguments (so most of them) return a shared object, because these objects are thread safe. So you don't need to worry about performance either.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!