Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7439113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:39:33+00:00 2026-05-29T10:39:33+00:00

I have a project which depends on several 3rd party libraries, the project itself

  • 0

I have a project which depends on several 3rd party libraries, the project itself is packaged as a jar and distributed to other developers as a library.
Those developers add the dependencies to their classpath and use my library in their code.

Recently I had an issue with one of the 3rd party dependencies, the apache commons codec libary,
The problem is this:

byte[] arr = "hi".getBytes();
// Codec Version 1.4
Base64.encodeBase64String(arr) == "aGk=\r\n" // this is true

// Codec Version 1.6
Base64.encodeBase64String(arr) == "aGk=" // this is true

As you can see the output of the method has changed with the minor version bump.

My question is, I don’t want to force the user of my library to a specific minor version of a 3rd party library. Assuming I know about the change to the dependent library, is there anyway in which I can recognize which library version is being included in the classpath and behave accordingly? or alternatively, what is considered to be the best practice for these kind of scenarios?

P.S – I know that for the above example I can just use new String(Base64.encodeBase64(data, false)) which is backwards compatible, this is a more general question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:39:34+00:00Added an answer on May 29, 2026 at 10:39 am
    package stackoverflow;
    
    import org.apache.commons.codec.binary.Base64;
    
    public class CodecTest {
        public static void main(String[] args) {
            byte[] arr = "hi".getBytes();
            String s = Base64.encodeBase64String(arr);
            System.out.println("'" + s + "'");
            Package package_ = Package.getPackage("org.apache.commons.codec.binary");
            System.out.println(package_);
            System.out.println("specificationVersion: " + package_.getSpecificationVersion());
            System.out.println("implementationVersion: " + package_.getImplementationVersion());
        }
    }
    

    Produces (for v1.6):

    'aGk='
    package org.apache.commons.codec.binary, Commons Codec, version 1.6
    specificationVersion: 1.6
    implementationVersion: 1.6
    

    Produces (for v1.4):

    'aGk=
    '
    package org.apache.commons.codec.binary, Commons Codec, version 1.4
    specificationVersion: 1.4
    implementationVersion: 1.4
    

    So you could use the package object to test.

    But I would say that it’s a bit naughty for the API to have changed the way it did.

    EDIT Here is the reason for the change – https://issues.apache.org/jira/browse/CODEC-99.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: you have a zipped java project distribution, which depends on several libraries
I have a project which uses a large library residing in its own repository.
I have a project which has shared functionality between three other projects and have
I have maven project X which depends on project Y. when I run the
I have a project A which depends on artifact B. I made some hack
I have a Java project, Parent , which depends on a Child sub-project (in
We have several services, each of which should ideally operate independently of each other.
I have a project which is source controlled using Subversion and VisualSVN. Since the
I have a project which contains different components that everyone works on. We have
I have a project which it's domain contain following classes: Courier Customer Food Order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.