commons-bcel icon indicating copy to clipboard operation
commons-bcel copied to clipboard

BCEL-341: Oak class file patch

Open Hippo opened this issue 4 years ago • 14 comments

Patches a bug when parsing oak class files (versions <= 45.2)

The code attribute's maxStack, maxLocals, codeLength is half the size (u2 -> u1, u4 -> u2)

Hippo avatar Aug 09 '20 07:08 Hippo

Note: All test pass with mvn clean verify

Hippo avatar Aug 09 '20 08:08 Hippo

-1 for now:

  • Fails the build due to a checkstyle error: https://travis-ci.org/github/apache/commons-bcel/jobs/716255992
  • No unit tests. One or more unit tests should fail without the patch to the main folder.
  • The implementation feels at first glance like a class file version specific brute force hack using conditionals and booleans, as opposed to a more object oriented solution. Needs more study on my side as well.

garydgregory avatar Aug 10 '20 15:08 garydgregory

I will look into the check style error, and ill add a unit test. But as far as it being a version specific brute force hack is well, because this only occurs when one condition is met.

Take a look here https://github.com/ItzSomebody/openjdk-jdk8u/blob/e87709def542f064a7ab9fa75542230e40876310/hotspot/src/share/vm/classfile/classFileParser.cpp#L2137

But if you really want me to give an oop approach on it I will do so.

Hippo avatar Aug 10 '20 20:08 Hippo

I think we should also have a class file or jar file that we can run through other existing tests.

garydgregory avatar Aug 10 '20 21:08 garydgregory

Since this is just support for oak class files, do I really need to write a test for it? Can't I just use the existing test cases?

Hippo avatar Aug 10 '20 21:08 Hippo

OakFile.class.zip

This is an oak class file that BCEL fails to parse without my patches, I fixed the checkstyle error. But I am still not sure how I feel about over complicating things with an oop system on weather to read a u1 or u2. But if that is what you want I will implement it once I get off work 👍

Hippo avatar Aug 10 '20 21:08 Hippo

Actually I just thought of a more stable way to implement this, I will do so when I get the chance.

Hippo avatar Aug 10 '20 22:08 Hippo

OakFile.class.zip

This is an oak class file that BCEL fails to parse without my patches, I fixed the checkstyle error. But I am still not sure how I feel about over complicating things with an oop system on weather to read a u1 or u2. But if that is what you want I will implement it once I get off work 👍

Thank you for the class file. I think we'll need the source to include it in the project repo to make sure the licensing is OK for an Apache project.

garydgregory avatar Aug 11 '20 00:08 garydgregory

OakFile.java.zip

There is no license, it's practically a hello world program.

Hippo avatar Aug 11 '20 03:08 Hippo

I realized that my idea for making it "more stable" would require a massive overhaul on the library, which doesn't seem like a good idea. I can think of a different approach if you would like, though I personally don't think its necessary.

Hippo avatar Aug 11 '20 03:08 Hippo

OakFile.java.zip

There is no license, it's practically a hello world program.

Hi @Hippo I'll should be able to take a look this weekend to see if a cleaner approach can be devised. In the meantime, please provide the source .java and instructions on how you created the class file if it is out of the ordinary Java tooling we are all used to. Is there an Oak/Java 1.0 compiler you used we can download to create additional files?

garydgregory avatar Aug 11 '20 12:08 garydgregory

Notes From: https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html footnote 1:

The Java virtual machine implementation of Sun's JDK release 1.0.2 supports class file format versions 45.0 through 45.3 inclusive. Sun's JDK releases 1.1.X can support class file formats of versions in the range 45.0 through 45.65535 inclusive. Implementations of version 1.2 of the Java 2 platform can support class file formats of versions in the range 45.0 through 46.0 inclusive.

garydgregory avatar Aug 11 '20 13:08 garydgregory

Any updates?

Hippo avatar Sep 19 '20 07:09 Hippo