byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

Eclipse project compilation error using mockito and byte-buddy

Open ivenhov opened this issue 1 year ago • 5 comments

Hi

I'm using Eclipse Version: 2024-06 (4.32.0) In my Gradle-based Java 1.8 project I have mockito 4.11.0

testImplementation 'org.mockito:mockito-core:4.11.0'

This brings in byte-buddy 1.12.19 and the same version of byte-buddy-agent

Eclipse flags an error on the project as below Screenshot 2024-08-07 at 11 23 10

I started to narrow it down by forcing byte-buddy version as below

configurations.all {
    resolutionStrategy {
        force 'net.bytebuddy:byte-buddy:1.12.10'
        force 'net.bytebuddy:byte-buddy-agent:1.12.10'
    }
}

It still fails with version 1.12.10 and 1.14.18 but there are no error when I switch net.bytebuddy:byte-buddy to 1.12.9

As far as I know byte-buddy is build as a multi-release jar and it's been like that for quite some time.

Any help with this would be much appreciated. Daniel

ivenhov avatar Aug 07 '24 10:08 ivenhov

The module-info.class file needs to be compiled in Java 9, otherwise it won't work. The file is however placed in a sub-folder for multi-release jars. This seems to be an error in Eclipse.

raphw avatar Aug 07 '24 13:08 raphw

Thanks Raf I've checked that info file earlier for both version 1.12.9 and 1.12.10 and both show the same

javap -verbose 1.12.9/META-INF/versions/9/module-info.class | grep -i version
Classfile /private/tmp/jars/1.12.9/META-INF/versions/9/module-info.class
  minor version: 0
  major version: 53
javap -verbose 1.12.10/META-INF/versions/9/module-info.class | grep -i version
Classfile /private/tmp/jars/1.12.10/META-INF/versions/9/module-info.class
  minor version: 0
  major version: 53

I'm not sure what else would be different between those two and why one would be OK but not the other I've deleted /Users/daniel/.gradle/caches/modules-2/files-2.1/net.bytebuddy/ but the problem comes back

ivenhov avatar Aug 07 '24 13:08 ivenhov

That is strange. I will try to look into it once I find some time. Could you try to remove the module-info.class from the jar and see if it fixes the error? Just to be sure that this really is the issue.

raphw avatar Aug 09 '24 22:08 raphw

Good idea. I reproduced the same problem with 1.12.9 I unpacked the jar using jar xvf byte-buddy-1.12.9.jar

then repackaged it using both Java 8 and Java 11 (switching using sdkman), still keeping 1.12.9/META-INF/versions/9/module-info.class jar cvf ~/Downloads/byte-buddy-1.12.9-custom-java8.jar -C 1.12.9/ . Jar packaged with Java 8 does not get flagged with the errors in Eclipse but packaged with Java 11 does. Interestingly it does not matter whether META-INF/versions/9/module-info.class is included or not. Removing META-INF/version and packaging with Java 11 still flags the jar. This would suggest jar in 1.12.10 was packages with Java 9/11 but previous were with Java 8?

Clases themseleves are compiled to version 49, example

public interface net.bytebuddy.NamingStrategy
  minor version: 0
  major version: 49

Regards Daniel

ivenhov avatar Aug 13 '24 08:08 ivenhov

No, they are all built on GitHub Actions using a Java 8 JDK. That is really strange, is this something the Eclipse team can give an explanation on?

raphw avatar Aug 13 '24 10:08 raphw

I've done some further testing of this I managed to reproduce the problem in basic Java 8 project (no Gradle) and with using only bytebuddy as a dependency. I'm still repackaging bytebuddy v 1.12.9 but this time using jar cvmf META-INF/MANIFEST.MF ~/byte-buddy-1.12.9-repackaged-java-11-custom.jar . and similar commands

I think previous jar command to repackage was incorrect since it was overwriting manifest rather than re-using it.

The result is that

  • packaging with Java 11 creates incompatible jar if /META-INF/versions/9/module-info.class is present
  • Java 11 with no /META-INF/versions generates compatible class
  • Java 8 with /META-INF/versions generates compatible class

To me it looks like Eclipse's compiler is looking into versions/module-info.class even for Java 8 project, which I think it should not do. But it still does not explain the why official 1.12.9 would be compatible but 1.12.10 is not

There is a per-project setting to treat incompatible binaries as warnings instead of errors but that may mask other issues

I found related https://github.com/eclipse-m2e/m2e-core/issues/1806 https://github.com/junit-team/junit5/issues/3619

ivenhov avatar Sep 11 '24 21:09 ivenhov

Looking at this change set: https://github.com/raphw/byte-buddy/compare/byte-buddy-1.12.9...byte-buddy-1.12.10 I can only guess that this has something to do with updating the Maven Shade plugin. That is the only thing that is involved in these two releases.

Somehow, however, I assume that this is a bug in Eclipse that is triggered by a random difference. It would be curious if they could find out what is wrong. Both jars look correct to me.

raphw avatar Sep 13 '24 18:09 raphw