Skip to content

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

@mkouba

Description

@mkouba

If there is a class like (I know $ in the name is discouraged but still...):

public class Top$Notch {}

Then the following test will fail:

public class ClassInfoSimpleNameTest {

    @Test
    public void test() throws IOException {
        Index index = Index.of(Foo$Bar.class, Top$Notch.class);
        ClassInfo foo = index.getClassByName(Foo$Bar.class);
        assertEquals("Foo$Bar", foo.simpleName());
        ClassInfo top = index.getClassByName(Top$Notch.class);
        assertEquals("Top$Notch", top.simpleName());
    }

    public static class Foo$Bar {
    }

}

with ClassInfoSimpleNameTest.test:19 expected: <Top$Notch> but was: <Notch>.

In other words, for nested Foo$Bar the ClassInfo#simpleName() returns the correct simple name but for Top$Notch the DotName#local() is called and it returns Notch. I wonder if DotName#withoutPackagePrefix() should not be used for top-level classes instead?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions