numenta/htm.java

Dependency conflicts on com.fasterxml.jackson.core:jackson-core, leading to invoking unexpected methods

HelloCoCooo opened this issue · 1 comments

Hi, @cogmission, in htm.java-0.6.13-alpha, duplicate classes with the same fully-qualified name com.fasterxml.jackson.core.json.JsonWriteContext are included in two different libraries, i.e., com.fasterxml.jackson.core:jackson-core:2.5.3 and com.fasterxml.jackson.core:jackson-core:2.4.4.

According to "first declaration wins" class loading strategy, only this class in com.fasterxml.jackson.core:jackson-core:2.4.4 can be loaded, and that in com.fasterxml.jackson.core:jackson-core:2.5.3 will be shadowed.

By further analyzing, your project expects to invoke method <com.fasterxml.jackson.core.json.JsonWriteContext: writeFieldName(Ljava/lang/String;)I> in com.fasterxml.jackson.core:jackson-core:2.5.3. As it has been shadowed, so that this method defined in com.fasterxml.jackson.core:jackson-core:2.4.4 is actually forced to be referenced via the following invocation path:

<org.numenta.nupic.encoders.MultiEncoder: setLearning(Z)V> /home/wwww/sensor/unzip/htm.java-0.6.13-alpha/target/classes
<com.fasterxml.jackson.databind.MappingIterator: next()Ljava/lang/Object;> /home/wwww/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.4/jackson-databind-2.4.4.jar
<com.fasterxml.jackson.databind.MappingIterator: nextValue()Ljava/lang/Object;> /home/wwww/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.4/jackson-databind-2.4.4.jar
<com.fasterxml.jackson.databind.deser.BeanDeserializer: deserialize(Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;Ljava/lang/Object;)Ljava/lang/Object;> /home/wwww/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.4/jackson-databind-2.4.4.jar
<com.fasterxml.jackson.databind.deser.BeanDeserializer: deserializeWithUnwrapped(Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;Ljava/lang/Object;)Ljava/lang/Object;> /home/wwww/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.4/jackson-databind-2.4.4.jar
<com.fasterxml.jackson.databind.util.TokenBuffer: writeFieldName(Ljava/lang/String;)V> /home/wwww/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.4/jackson-databind-2.4.4.jar
<com.fasterxml.jackson.core.json.JsonWriteContext: writeFieldName(Ljava/lang/String;)I>

Although both of these two conflicting classes contain the referenced methods (with the same signature), they have different implementations. This issue will not lead to runtime crashes, but it can introduce inconsistent semantic hehavior by changing the control flows and data flows.

Workaround solution:
Use the newer version com.fasterxml.jackson.core:jackson-core:2.5.3 com.fasterxml.jackson.core:jackson-annotations:jar:2.5.3:compile com.fasterxml.jackson.core:jackson-databind:jar:2.5.3:compile to keep the version consistency.

Dependency tree--

[INFO] org.numenta:htm.java:jar:0.6.13
[INFO] +- joda-time:joda-time:jar:2.5:compile
[INFO] +- com.chaschev:chutils:jar:1.4:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | - org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- net.sf.trove4j:trove4j:jar:3.0.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
[INFO] | +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile - omitted for conflict with 2.4.4)
[INFO] | - (com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile - omitted for duplicate)
[INFO] +- org.slf4j:slf4j-api:jar:1.7.10:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.2:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.1.2:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.6:test - omitted for conflict with 1.7.10)
[INFO] +- io.reactivex:rxjava:jar:1.0.10:compile
[INFO] +- com.cedarsoftware:java-util:jar:1.19.3:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.1:compile
[INFO] | - org.apache.logging.log4j:log4j-core:jar:2.1:compile
[INFO] | - (org.apache.logging.log4j:log4j-api:jar:2.1:compile - omitted for duplicate)
[INFO] +- de.ruedigermoeller:fst:jar:2.45:compile
[INFO] | +- (com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile - omitted for conflict with 2.4.4)
[INFO] | +- org.javassist:javassist:jar:3.19.0-GA:compile
[INFO] | - org.objenesis:objenesis:jar:2.1:compile
[INFO] +- org.openjdk.jmh:jmh-core:jar:1.11.3:compile
[INFO] | +- net.sf.jopt-simple:jopt-simple:jar:4.6:compile
[INFO] | - org.apache.commons:commons-math3:jar:3.2:compile
[INFO] - algorithmfoundry:algorithmfoundry-shade-culled:jar:1.3:compile

Thank you very much.
Best,
Coco

Code snippet of :<com.fasterxml.jackson.core.json.JsonWriteContext: writeFieldName(Ljava/lang/String;)I> in com.fasterxml.jackson.core:jackson-core:2.5.3 (shadowed but expected to invoke method):

public int writeFieldName(String name) throws JsonProcessingException {		//line:152
  if (_gotName) {
    return JsonWriteContext.STATUS_EXPECT_VALUE;
  }
  _gotName = true;
  _currentName = name;
  if (_dups != null) { _checkDup(_dups, name); }
  return (_index < 0) ? STATUS_OK_AS_IS : STATUS_OK_AFTER_COMMA;
}

Code snippet of**:<com.fasterxml.jackson.core.json.JsonWriteContext: writeFieldName(Ljava/lang/String;)I>** in com.fasterxml.jackson.core:jackson-core:2.4.4 (loaded version):

public final int writeFieldName(String name) throws JsonProcessingException {		//line:117
  _gotName = true;
  _currentName = name;
  if (_dups != null) { _checkDup(_dups, name); }
  return (_index < 0) ? STATUS_OK_AS_IS : STATUS_OK_AFTER_COMMA;
}

As a result, these conflicting method included in com.fasterxml.jackson.core:jackson-core:2.5.3 deals with different cases, which changes the control flows and data flows. So being forced to use these methods in com.fasterxml.jackson.core:jackson-core:2.4.4 may lead to inconsisitent semantic behaviors.