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

"Unable to locate field type" error when annotations below @PropertyDefinition contain newlines #174

Closed
lourish opened this issue Jul 31, 2017 · 3 comments

Comments

@lourish
Copy link

lourish commented Jul 31, 2017

Hi, I have a property definition with JPA annotations of the form:

@Entity
@BeanDefinition(builderScope = "public")
public class MyDomainObject implements Bean {

    @PropertyDefinition
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinTable(name = "MY_JOIN_TABLE",
            inverseJoinColumns = { @JoinColumn(name = "AN_ID") },
            joinColumns = { @JoinColumn(name = "ANOTHER_ID") })
    private MyObject myObject;

Upon saving in eclipse I get "Unable to locate field type at line X", if I remove the nested @joincolumn lines it works. It also works if there's one nested @joincolumn annotation on a single line.

Maven plugin version 1.1, joda beans version 1.13.

This issue was originally posted at JodaOrg/joda-beans-maven-plugin#4

@lourish
Copy link
Author

lourish commented Aug 10, 2017

I've discovered that this happens any time the @PropertyDefinition annotation is above another annotation containing newlines. So the following will also fail:

    @PropertyDefinition
    @OneToMany(fetch = FetchType.EAGER,
            cascade = CascadeType.ALL,
            orphanRemoval = true)
    @JoinColumn
    private MyObject myObject;

The workaround is to ensure that the @PropertyDefinition annotation is directly before the field declaration.

@lourish lourish changed the title "Unable to locate field type" error with nested annotations "Unable to locate field type" error when annotations below @PropertyDefinition contain newlines Aug 10, 2017
@jodastephen
Copy link
Member

This is a known limitation of the parser. Rather than trying to parse the whole source file as Java, it looks for specific known things, but as part of that the developer must write code that is of a standard form. Here, it looks for the @ sign at the start of each line following the @PropertyDefinition. When it stops finding it, it assumes that it has found the field.

I've made a change so it looks for a comma at the end of the previous line and uses that to assume a multi-line annotation. While still imperfect, it should handle the cases above and not break any existing code.

@lourish
Copy link
Author

lourish commented Sep 20, 2017

Thanks Stephen, that's good enough for me.

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

No branches or pull requests

2 participants