Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name parameter to TypePool#describe(String) has no contract #1754

Open
ljnelson opened this issue Jan 18, 2025 · 7 comments
Open

name parameter to TypePool#describe(String) has no contract #1754

ljnelson opened this issue Jan 18, 2025 · 7 comments
Assignees
Labels
Milestone

Comments

@ljnelson
Copy link
Contributor

https://github.com/raphw/byte-buddy/blob/byte-buddy-1.16.0/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java#L576-L602

The documentation says only:

name - The name of the type to describe. The name is to be written as when calling Class.getName().

When you call Class.getName(), you supply no arguments, so it's hard to know how calling it could describe the name parameter of TypePool#describe(String).

Maybe you meant, loosely, Class.forName(String)? But Class.forName("int") will fail, whereas typePool.describe("int") will succeed.

Then it appears that certain? all? only some? implementations of TypePool#describe(String) will accept Java Virtual Machine ArrayTypeSignatures, as in something like [java.lang.Integer whereas Class.forName("[java.lang.Integer") will fail. Is this name form officially supported, or just an implementation detail?

What, then, should the documentation for the name parameter of TypePool#describe(String) be?

@raphw
Copy link
Owner

raphw commented Jan 18, 2025

The idea is that you can call the method on the class constant. For example:

MyClass.class.getName()

or

int[][][].class.getName()

Did you observe that this does not apply?

@raphw raphw added the question label Jan 18, 2025
@raphw raphw added this to the 1.15.11 milestone Jan 18, 2025
@raphw raphw self-assigned this Jan 18, 2025
@ljnelson
Copy link
Contributor Author

Maybe I was not clear. If I call someTypePool.describe("int"), it works; I get a TypeDescription representing int. If I call someTypePool.describe("[I"), it works; I get a TypeDescription representing int[]. If I call someTypePool.describe("[Qjava.lang.Integer!") it works; I get a TypeDescription representing java.lang.Integer[]. What do these names have in common? Where is it described what is a legal input and what is not?

@raphw
Copy link
Owner

raphw commented Jan 18, 2025

This is indeed a sloppyness in the input validation. For a non-primitive array, it does not currently check that the input starts with an L and ends with a ; as it is done for toString on type representations, but simply cuts the first and last character.

I will add validation that it checks for well-formed input in the future.

@ljnelson
Copy link
Contributor Author

Next up, if I wanted a TypeDescription for a nested class, do I use dollar signs or periods? e.g. typePool.describe("com.foo.Bar$Baz") or typePool.describe("com.foo.Bar.Baz")? (I know I can try it out, but I should be able to understand what is legal input and what is not from the documentation (the contract).)

@raphw
Copy link
Owner

raphw commented Jan 18, 2025

Dollar signs, just as the toString implementation of Class. Have Class.toString as a reference.

@ljnelson
Copy link
Contributor Author

Hmm; OK, but Class#toString() says that "class " will always be in the output. Anyway, it would be nice if the javadoc listed what rules an argument for the name parameter of the TypePool#describe(String) method needs to follow. Thanks!

@raphw
Copy link
Owner

raphw commented Jan 19, 2025

That is true. The prefix is omitted. As if getName() was called, as the javadoc says.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants