Support class versions - #1418
Conversation
Add the class version to JavaClass so rules can verify the class version
|
I followed the guidelines in the original issue, but was unsure about testing. How would you advise testing this? |
|
One option could be to commit compiled classes in |
|
Do you have an example test method/class I should follow the style/pattern of? |
| * @return The Java version | ||
| */ | ||
| public int getJavaVersion() { | ||
| return major - 44; |
There was a problem hiding this comment.
to be a bit nitpicky:
Do you consider the version old java versions 1.0, 1.1, ... as 1, 1, 2?
https://javaalmanac.io/bytecode/versions/
Java 1.0 -> class file version 45.0 -> java version 1
Java 1.1 -> class file version 45.3 -> java version 1
Java 1.2 -> class file version 46.0 -> java version 2
...
starting from Java5 you calculation works perfectly fine, before that the numbering is already weird on java side.
Do we ignore this since these version are so ancient that we can't expect anyone to stumble over java classes compiled before java 5?
Since even Java 8 is currently dyng, this should be fine
There was a problem hiding this comment.
We don't officially support anything older than Java 8, so a minor inaccuracy in on something this old is fully acceptable to me. However, we may want to document where this magic value of 44 comes from, e.g. like this:
| return major - 44; | |
| // see e.g. https://javaalmanac.io/bytecode/versions/; Java 2 has class file version 46 etc. | |
| return major - 44; |
|
A test would be really great for this, including the LTS versions starting from Java 8: 8, 11, 17, 21, 25 |
schulzjo-tng
left a comment
There was a problem hiding this comment.
This looks good! I think adding tests shouldn't be too hard, since we already have some Java-version-specific tests (see e.g. here):
ArchUnit/archunit/build.gradle
Lines 61 to 63 in 6466ac3
Adding one test case for each of those should be good enough (e.g. Java 8, 9, 16, 25)
Add the class version to JavaClass so rules can verify the class version
Fixes #423