11

I have created WS02MB project. Inside that project I have used net.sf.json.JSONObject, accumulate method above error occur. Please advise how to resolve this issue.

Sample code:-

JSONObject json = new JSONObject();
String pair= "{long sting here}";//11586 letter count
json.accumulate("message", pair); 

I have used following jar file:-

andes-client-3.1.1.jar
commons-beanutils.jar
commons-collections-3.2.1.jar
commons-lang.jar
commons-lang3-3.5.jar
commons-logging-1.2.jar
ezmorph-1.0.6.jar
geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
json-lib-2.4-jdk15.jar
log4j-1.2.13.jar
org-apache-commons-codec.jar
org-apache-commons-logging.jar
org.eclipse.paho.client.mqttv3-1.0.2.jar
org.wso2.carbon.logging-4.4.1.jar
org.wso2.securevault-1.0.0-wso2v2.jar

Error Message:-

java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.isBlank(Ljava/lang/String;)Z
at org.apache.commons.lang.math.NumberUtils.createNumber(NumberUtils.java:500)
at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:417)
at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1008)
at net.sf.json.JSONObject._fromString(JSONObject.java:1201)
at net.sf.json.JSONObject.fromObject(JSONObject.java:165)
at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:139)
at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:262)
at net.sf.json.JSONObject._processValue(JSONObject.java:2655)
at net.sf.json.JSONObject.processValue(JSONObject.java:2721)
at net.sf.json.JSONObject.setInternal(JSONObject.java:2736)
at net.sf.json.JSONObject._accumulate(JSONObject.java:2635)
at net.sf.json.JSONObject.accumulate(JSONObject.java:1543)
1
  • 5
    Every time you see something like noSuchMethod it's the sign you're using different or two libraries in classpath. So now to the point: At compile time check what library requires what jar. (If you use maven\gradle there're command to show graph tree). Then Compare then with RUNTIME libs. You can see which lib requireS another one by exception stacktrace. To find the required lib you need YourClass.class.getClassloader.getResource('package.YourClass.class. So thus you will understand why this exception has occurred. Commented Jan 5, 2017 at 22:39

3 Answers 3

26

Finally I found the issue, This is due to commons-lang.jar and commons-lang3-3.5.jar conflict. So I have removed commons-lang.jar from Gradle task. Now it is working without any issue.

Sign up to request clarification or add additional context in comments.

Comments

2

I got the same error with a Maven build. I accidentally imported commons.lang utility, when I should have imported commons.lang3. I would have thought this would be caught in the compile/build phase and not as a runtime exception.

Comments

1

None of these other solutions solved my issue. My issue was that another commons-lang dependency (a lower version) was being pulled in by another dependency. If you open the dependency hierarchy in eclipse and search for org.apache.commons.lang you should be able to find the dependency that is pulling it in. Add an exclusion under that dependency in the pom as follows:

<dependency>
    <groupId>Problem dependency group</groupId>
    <artifactId>Problem dependency</artifactId>
    <version>1.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.commons</groupId>
            <artifactId>org.apache.commons.lang</artifactId>
        </exclusion>
    </exclusions>
</dependency>

This should stop the problem dependency from pulling in the other version of commons-lang and should fix the noSuchMethodError.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.