Bytecode enhancement using ByteBuddy fails when the class is not available from the provided ClassLoader

Description

When ByteBuddy is used for bytecode enhancement, and Enhancer#enhance is used to enhance bytecode that is not available from the provided ClassLoader, enhancement will fail due to IllegalStateException.

This happens because ByteBuddy attempts to locate the bytecode from the ClassLoader via ClassLoader.getResourceAsStream, instead of just using the bytecode provided to Enhancer#enhancer with the originalBytes argument.

When {{ClassLoader.getResourceAsStream returns null, net.bytebuddy.dynamic.ClassFileLocator#locate returns a ClassFileLocator.Resolution.Illegal object.

ClassFileLocator.Resolution.Illegal#resolve ultimately throws IllegalStateException.

Environment

None

Status

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.4.2
5.3.9

Priority

Major