Open suztomo opened 5 years ago
The issue of course is that ClassPath.getTopLevelClasses()
assumes that a class is nested if it has $
in its name. If a class Bar
is nested inside com.example.Foo
then its full name will be com.example.Foo$Bar
, but it is perfectly legal to define a class whose actual name is Foo$Bar
. So the heuristic that getTopLevelClasses()
uses cannot work in general. I believe the only way to be sure would be to look for the InnerClasses
attribute inside the .class
file, and that implies that this method would become quite a bit slower and more complicated. Alternatively, we could disregard sequences of $
characters at the beginning and end of a class name when determining nestedness. That would cover the case at hand, while still not being a general solution.
Thank you for response. Our project (cloud-opensource-java) will use getAllClasses
instead. So I don't expect Guava to implement something specific to Autovalue.
@eamonnmcmanus
Alternatively, we could disregard sequences of
$
characters at the beginning and end of a class name when determining nestedness.
I guess, doing this would be a clear improvement for a minimum cost.
You could also use a heuristics like "when there's no Foo
, then Foo$Bar
is not a nested class" (which also takes care of the leading dollar). This feels pretty hacky, but solves cases like "sometool" generating sometool$SomeClass
(I can't recall where I saw it and if it really looked like this).
@netdpb and I found that ClassPath.getTopLevelClasses() does not return top-level class with $ character in its name. Example class:
com.google.cloud.bigquery.$AutoValue_Labels
in google-cloud-bigquery-1.56.0.jar.Test case
JLS 3.8 states that dollar sign ('$') is a valid Java letter.
AutoValue has
@Memoized
annotation, which creates class$AutoValue_XXXX
andAutoValue_XXXX extends $AutoValue_XXXX
in the same package.