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

Make sure J.Erroneous is only used when appropriate #5094

Open
knutwannheden opened this issue Feb 25, 2025 · 0 comments
Open

Make sure J.Erroneous is only used when appropriate #5094

knutwannheden opened this issue Feb 25, 2025 · 0 comments
Labels
bug Something isn't working parser-java

Comments

@knutwannheden
Copy link
Contributor

The J.Erroneous support in the Java parser allows the parser to create J.Erroneous nodes whenever some illegal Java syntax is encountered. This however only works when the J.Erroneous type is compatible with the receiving property. For property values wrapped in something like a JRightPadded this will not be checked by the JVM due to Java's type erasure. So for the following example it would be illegal to return a J.Erroneous instead of a J.Import as the parser currently does:

package foo;

import ${hello}.client;

class Foo {}

A source file like this would not compile, but it might appear in a src/main/resources folder as in this example.

One solution could be to add a Class<? extends J> parameter to the convert() method and then the method would throw an exception whenever the result it returns isn't compatible with that type. As a result the parser would then return a ParseError instead of a broken LST model.

See also Slack discussion.

@knutwannheden knutwannheden added the bug Something isn't working label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-java
Projects
Status: No status
Development

No branches or pull requests

1 participant