raphw/byte-buddy

Redefinition fails with "java.lang.IllegalStateException: Illegal parameter name"

Closed this issue · 6 comments

I had a working redefinition of org.gradle.configurationcache.DefaultConfigurationCache using the gradle 8.8 API. This fails at runtime with gradle 8.9 (the class was renamed to org.gradle.internal.cc.impl.DefaultConfigurationCache in 8.9).

Reproducer below

Stack trace

Exception in thread "main" java.lang.IllegalStateException: Illegal parameter name of org.gradle.internal.cc.impl.DefaultConfigurationCache <this> for private static java.lang.Object org.gradle.internal.cc.impl.DefaultConfigurationCache.getStore$delegate(org.gradle.internal.cc.impl.DefaultConfigurationCache)
	at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1769)
	at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:519)
	at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.toTypeWriter(RedefinitionDynamicTypeBuilder.java:213)
	at net.bytebuddy.dynamic.scaffold.inline.AbstractInliningDynamicTypeBuilder.toTypeWriter(AbstractInliningDynamicTypeBuilder.java:127)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$UsingTypeWriter.make(DynamicType.java:4057)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3741)

https://github.com/mgroth0/byte-buddy-1709

In order to reproduce, edit gradle-wrapper.properties to specify the gradle version as 8.8 and execute ./gradlew run, then change the gradle version to 8.9 and run again. You should see a no error in 8.8, and an error in 8.9.

You can disable validation by setting a custom entry point in byteBuddy { }. Disable validation here.

Thanks @raphw . I disabled validation and this seemed to prevent the error.

A couple notes

  • I'm unsure if this is what youd consider a solution or just a workaround. Perhaps this would ideally work without having to disable validation? Or alternately, a simpler change that could be made might be to edit the error message to indicate to the user that they can prevent the error by disabling type validation. If I didn't come here to ask, I don't I'd ever figure out on my own how to solve the error.
  • This might be irrelvant, but just FIY I'm not using the byte buddy gradle plugin so the byteBuddy { } syntax doesn't apply for me. I just used ByteBuddy().with(TypeValidation.DISABLED).

The closer you come to current versions of Gradle and Groovy or Kotlin, the less this is an issue. In the older versions, a lot of metadata in these classes is however corrupt, and since this can affect the outcome of instrumentation, this default is chosen.

Oh that's interesting. But you realize that it was the other way around here, right? Everything worked fine up to and including Gradle 8.8. Broke in Gradle 8.9.

There is of course regressions. The idea is that you cannot call a parameter of a method this what is of course correct. Ideally, it captures only errors that are introduced by the user of Byte Buddy, but it does capture retained errors.