Skip to content

Support diffing Jar bytecode versions#168

Closed
Goooler wants to merge 9 commits intoJakeWharton:trunkfrom
Goooler:diff-byte-code-versions
Closed

Support diffing Jar bytecode versions#168
Goooler wants to merge 9 commits intoJakeWharton:trunkfrom
Goooler:diff-byte-code-versions

Conversation

@Goooler
Copy link
Contributor

@Goooler Goooler commented Aug 25, 2023

OLD: diffuse-0.2.0-SNAPSHOT-java11.jar (bytecodeVersion: 55)
NEW: diffuse-0.2.0-SNAPSHOT-java16.jar (bytecodeVersion: 60)

 JAR   │ old      │ new      │ diff
───────┼──────────┼──────────┼──────
 class │ 90.6 KiB │ 90.6 KiB │  0 B
 other │     96 B │     96 B │  0 B
───────┼──────────┼──────────┼──────
 total │ 90.7 KiB │ 90.7 KiB │  0 B

 CLASSES │ old │ new │ diff
─────────┼─────┼─────┼───────────
 classes │  24 │  24 │ 0 (+0 -0)
 methods │ 234 │ 234 │ 0 (+0 -0)
  fields │  78 │  78 │ 0 (+0 -0)

=================
====   JAR   ====
=================

 size │ diff │ path
──────┼──────┼─────────
  0 B │  0 B │ (total)

@JvmName("parse")
fun Input.toClass(): Class {
val reader = ClassReader(toByteArray())
val bytecodeVersion = reader.readShort(0 + 6)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to implement this for Dex files.

@Goooler Goooler mentioned this pull request Sep 5, 2023

class Jar private constructor(
override val filename: String?,
val bytecodeVersion: Short?,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I think we're going to drown in nuance here. Jars don't have bytecode versions, classes do. And multiple classes within a jar can have different versions. You can conditionally classload classes based on capabilities and those classes could be compiled for two different versions of Java. There's also the multi-version jar standard which puts classes of different versions into META-INF/versions/N/. The ordering of the classes in the jar (read: zip) could be effectively random so taking the first class may not be indicative of what the majority of classes were compiled with.

I'm happy to discuss strategies for surfacing this information, but as-is I think this is too simple of an implementation. Note that it probably works for 99.99% of jars, but when it fails it fails in a spectacularly wrong way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I count all the byte code versions in a Jar and filter the most one.

@Goooler Goooler closed this Aug 9, 2025
@Goooler Goooler deleted the diff-byte-code-versions branch August 9, 2025 12:13
@Goooler
Copy link
Contributor Author

Goooler commented Mar 8, 2026

Addressing a new fix to #473.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants