javaparser / javasymbolsolver

*old repository* --> this is now integrated in https://github.com/javaparser/javaparser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(Static) String parameter's type resolution throws

staslev opened this issue · comments

I'm using 0.52.

The offending statement looks roughly like so: foo(MY_STATIC_STRING) where MY_STATIC_STRING is a final static String. During the method invocation resolution process, MY_STATIC_STRING is also attempted to be resolved, but throws.

I followed the rabbit hole and got to JavaParserTypeDeclarationAdapter#solveType, where ancestor.getTypeDeclaration().internalTypes() throws since ancestor.getTypeDeclaration() is of type TypeDeclaration which throws by default upon invoking internalTypes().

I think that having a try-catch around the throwing block could be beneficial, since if we fail to look into extended classes and implemented interfaces for some reason, we might (should?) still try using the parent's context and do context.getParent().solveType(name, typeSolver). Moreover, in my particular use case it even properly resolves to java.lang.String if I do it manually, but the flow never reaches there since an exception is thrown at ancestor.getTypeDeclaration().internalTypes().

What do you think?

P.S.
Great tool, thanks for the hard work you're putting into it!

Just noticed 0.53 was out and tried it, the problem I was having has gone away!
Thanks again for the hard work and the great tool!

@staslev thank you so much for your detailed report and for using JavaSymbolSolver. I am very happy the problem has been solved in the last release. Please let us know of any further issue you face. It would also great if you wanted to share what you are building with JSS