raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.29k stars 807 forks source link

Unexpected type reference on method: 19 #1509

Closed lanicc closed 1 year ago

lanicc commented 1 year ago

Similar to #1372.

During an instrumentation process Listener find error. typeName[com.xx.CloudAccountUpdateReq]

ERROR

java.lang.IllegalStateException: Unexpected type reference on method: 19
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default$TypeExtractor$MethodExtractor.visitTypeAnnotation(TypePool.java:7931)
        at com.souche.tracer.net.bytebuddy.jar.asm.ClassReader.readMethod(ClassReader.java:1221)
        at com.souche.tracer.net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:688)
        at com.souche.tracer.net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:400)
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default.parse(TypePool.java:683)
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default.doDescribe(TypePool.java:667)
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default$WithLazyResolution.access$001(TypePool.java:747)
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default$WithLazyResolution.doResolve(TypePool.java:845)
        at com.souche.tracer.net.bytebuddy.pool.TypePool$Default$WithLazyResolution$LazyTypeDescription.delegate(TypePool.java:914)
        at com.souche.tracer.net.bytebuddy.description.type.TypeDescription$AbstractBase$OfSimpleType$WithDelegation.getPackage(TypeDescription.j
ava:8101)
        at com.souche.agent.core.match.OldTracerMatcher$1.matches(OldTracerMatcher.java:27)
        at com.souche.agent.core.match.OldTracerMatcher$1.matches(OldTracerMatcher.java:23)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$RawMatcher$ForElementMatchers.matches(AgentBuilder.java:1275)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$RawMatcher$Disjunction.matches(AgentBuilder.java:1167)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.matches(AgentBuilder.java:9974)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.resolve(AgentBuilder.java:9987)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Compound.resolve(AgentBuilder.java:10195)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.resolve(AgentBuilder.java:10527)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10494)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10457)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10223)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10833
)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10780)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.souche.tracer.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10380)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)

class CloudAccountUpdateReq is

import com.xx.CloudAccountDiscountDTO;
import lombok.Data;

import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

@Data
public class CloudAccountUpdateReq implements Serializable {

    private Long id;

    private String note;

    private List<String> regionList;

    private List<@Valid CloudAccountDiscountDTO> discountList;

}

The field discountList is annotated with @Valid.

But, this way it works normally.

  @Valid
  private List<CloudAccountDiscountDTO> discountList;

I tested with version 1.12.18, 1.14.6 for testing and still reported the error.

raphw commented 1 year ago

I would assume that the JVM would also fail if you tried to reqd the annotations of that type. It seems like some type adds an illegal value to the annotation.

lanicc commented 1 year ago

I would assume that the JVM would also fail if you tried to reqd the annotations of that type. It seems like some type adds an illegal value to the annotation.

It works as expected. It's a feature of Bean Validation called Container element constraints:

raphw commented 1 year ago

Can you create a stand-alone example for me, then I am happy to look into it.

raphw commented 1 year ago

I also just checked the line number. It does not seem like that you are using the latest version of Byte Buddy. Could you try updating first?

lanicc commented 1 year ago

Sorry for my mistake. Version 1.14.0 is working fine