0

I sometimes facing dependency hell in Java. It is common known problem: library A depends on library C in version 2.5 and library B depends on C too, but in version 2.6. Then I have to solve question: Are two versions of C library backward compatible? Can I use libraries A, B and C in one application classpath? Or should I create "shaded bundle" of A with old version of C?

If two versions of C library are incompatible and I use it, application can be started usually. But then after some hours or days can "no such method" exception occurs! I would like to detect this problem before application start, not in runtime.

Question is: Exist some tool that can list all used symbols in class and all provided symbols by class? Then I can create script that detect used but missing symbols...

Karry
  • 381
  • 3
  • 4
  • I think you'll just have to find out if the newer version of the library is backwards compatible. No automated tool will be able to tell you that. The absence of missing symbols does not guarantee it. – Thilo May 19 '16 at 12:09
  • I know. It can't be fully automated. But found missing methods is good start... – Karry May 19 '16 at 13:22

3 Answers3

1

The javap command can list all symbols defined by a class.

The javap -c command shows external methods and fields used by a class as comments in the disassembled bytecodes. You might be able to unpicked them.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

One colleague suggest me migration manager (https://www.lightbend.com/community/core-tools/migration-manager), that shows binary incompatibility in classpath (two versions of one library). It isn't exactly what I wanted, but it helps a lot...

$java -jar migration-manager-cli-0.1.9.jar \
  --prev ~/.m2/repository/com/google/protobuf/protobuf-java/2.4.1/protobuf-java-2.4.1.jar  \
  --curr ~/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/protobuf-java-2.5.0.jar \
  --direction both

Found 393 binary incompatibilities
==================================
 * abstract method getNameBytes()com.google.protobuf.ByteString in interface
   com.google.protobuf.DescriptorProtos#ServiceDescriptorProtoOrBuilder is
   present only in current version

...
Karry
  • 381
  • 3
  • 4
1

Similar question being addressed here:

How to identify a missing method (Binary Compatibility) in a JAR statically

Quick googling revealed possible solution here:

http://vongosling.github.io/dependency-mediator/

(But I have no experience with the tool)

Community
  • 1
  • 1
JBG7
  • 11
  • 1