Skip to content

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

Open
@knutwannheden

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions