Skip to content

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented May 13, 2025

The simpleName() method used to return a wrong result in case of top-level classes with dollar $ in their names. For example, for the following class

public class Top$Level {
}

the ClassInfo.simpleName() method used to return Level. This commit fixes that by only calling name.local() in case the name is componentized (which it always is, so just to be sure) and is not marked inner. If it is marked inner, the simpleName() method calls name.withoutPackagePrefix().

It would be possible to call withoutPackagePrefix() always, but that method allocates in case of componentized names, which we want to avoid if possible.

Fixes #526

The `simpleName()` method used to return a wrong result in case of top-level
classes with dollar `$` in their names. For example, for the following class

```java
public class Top$Level {
}
```

the `ClassInfo.simpleName()` method used to return `Level`. This commit fixes
that by only calling `name.local()` in case the `name` is componentized (which
it always is, so just to be sure) and is _not_ marked inner. If it is marked
inner, the `simpleName()` method calls `name.withoutPackagePrefix()`.

It would be possible to call `withoutPackagePrefix()` always, but that method
allocates in case of componentized names, which we want to avoid if possible.
@Ladicek Ladicek added this to the 3.3.1 milestone May 13, 2025
@Ladicek Ladicek merged commit a48cd4c into smallrye:main May 13, 2025
35 checks passed
@Ladicek Ladicek deleted the fix-simplename branch May 13, 2025 08:31
@mkouba
Copy link
Contributor

mkouba commented May 13, 2025

It would be possible to call withoutPackagePrefix() always, but that method allocates in case of componentized names, which we want to avoid if possible.

I think that we can't use the withoutPackagePrefix() for nested classes because if you declare a nested class Bar on a top-level class Foo then the simple name should be Bar but DotName#withoutPackagePrefix() would return Foo$Bar, I guess...

@Ladicek
Copy link
Contributor Author

Ladicek commented May 13, 2025

Hmm, yeah, that's true. My bad. The comment is wrong. The code is right :-)

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

Successfully merging this pull request may close these issues.

ClassInfo#simpleName() behaves inconsistently for nested/top-level classes with a dollar sign in name
2 participants