Git Product home page Git Product logo

rootioreader's Introduction

RootIOreader

This program shows how to read ROOT files (https://root.cern/) using Java. It illustrates problems with the compatibility of JDK versions. This example shows that compiling this code using JDK 1.5 creates a functional package that can read the file "Example.root". The JDK 1.5 compiled package can be executed on new versions of JDK 1.8 - JDK 15. However, the package compiled using JDK 1.6 (and above) creates a jar file that cannot be used for reading such files.

This compatibility issue affects several projects: http://java.freehep.org/freehep-rootio/ (original library), Jas3 http://jas.freehep.org/jas3/, Root4j https://github.com/diana-hep/root4j, Jas4pp https://atlaswww.hep.anl.gov/asc/jas4pp/, DataMelt https://datamelt.org etc. The problem is likely related to the Apache-BCEL library and may affect other projects that rely on dynamic creation of Java classes.

The issue is visible on bugs.java.com under JDK-8261887 ticket number.

How to recreate this problem

git clone [email protected]:chekanov/RootIOreader.git
cd RootIOreader

This assumes Linux and installed JDK 1.8 that supports the JDK target/source version 1.5. Compile the package using JDK target=1.5:

ant

(the ant build tool should be installed). This creates the file "rootio.jar". Then run this package:

ant run

It will read objects from the file "Example.root".

Now change the target JDK version to 1.8. To do this, modify the line:

 <property name="jdkversion" value="1.5" />

to

<property name="jdkversion" value="1.8" />

in the file "build.xml" (it can be also 1.6, 1.7). Then compile the package again and run it:

ant clean; ant; ant run

It will return the error:

Object hep.io.root.proxy.TString has length=1025
     [java] Exception in thread "main" java.lang.ClassFormatError: Invalid code attribute name index 29 in class file hep/io/root/proxy/TString
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
     [java] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
     [java] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:877)
     [java] 	at hep.io.root.core.RootClassLoader.findClass(RootClassLoader.java:97)
     [java] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
     [java] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
     [java] 	at hep.io.root.core.GenericRootClass.getClass(GenericRootClass.java:143)
     [java] 	at hep.io.root.core.GenericRootClass.getProxyClass(GenericRootClass.java:162)
     [java] 	at hep.io.root.core.GenericRootClass.newInstance(GenericRootClass.java:97)
     [java] 	at hep.io.root.core.RootInputStream.readObject(RootInputStream.java:354)
     [java] 	at hep.io.root.core.FastInputStream.readObject(FastInputStream.java:269)
     [java] 	at hep.io.root.RootFileReader.init(RootFileReader.java:226)
     [java] 	at hep.io.root.RootFileReader.init(RootFileReader.java:157)
     [java] 	at hep.io.root.RootFileReader.<init>(RootFileReader.java:137)
     [java] 	at rootio.FileRoot.<init>(FileRoot.java:61)
     [java] 	at rootio.Main.main(Main.java:27)

Note the object length 1025 is different from 1003 when using JDK 1.5 compiled version.

If you use JDK13 - JDK15 versions for the above tests, the error message when compiling and running the code is different:

Object hep.io.root.proxy.TString has length=1025
     [java] Exception in thread "main" java.lang.ClassFormatError: LineNumberTable attribute has wrong length in class file hep/io/root/proxy/TString
     [java] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
...

Conclusion: Only JDK 1.5 can create a functional program that can read the file Example.root. Since JDK 1.8 (that supports the JDK 1.5 target) will be discontinued, this package cannot be used for future Java versions.

rootioreader's People

Contributors

chekanov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.