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

[BUG] Annotations cannot refer to generated FieldNameConstants #2350

Open
c-koell opened this issue Jan 29, 2020 · 7 comments
Open

[BUG] Annotations cannot refer to generated FieldNameConstants #2350

c-koell opened this issue Jan 29, 2020 · 7 comments

Comments

@c-koell
Copy link

c-koell commented Jan 29, 2020

Describe the bug
We use in our projects the @FieldNameConstants Annotations. The generated Contants are used on NamedEntityGraph Annotations like
@NamedEntityGraph(name = "test", attributeNodes = { @NamedAttributeNode(EnityXY.Fields.geschaeftszahl),

If we use JDK8 to compile the poject all works fine. After switching the jdk (not the compile level)
we are unable to copile the project. In Eclipse the compilation works fine with jdk8 and jdk 11

Expected behavior
It would be fine if the project will also copile with a JDK11.

Version info (please complete the following information):

  • Lombok version 1.18.10
  • Maven Compiler 3.8.1
@c-koell
Copy link
Author

c-koell commented Jan 29, 2020

Hi ..

Digging more into this Problem i found the main problem.
This simple Entity has no problems to compile.

@Entity
@Getter
@Setter
@FieldNameConstants
@NamedEntityGraph(name = "Test", attributeNodes = {@NamedAttributeNode(TestTable.Fields.name)})
public class TestTable implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	private Integer id;
	private String name;
	private String value;

}

But if i use the NamedEntityGraph Annotation as Repeatable Annotation the class is not compilable

@Entity
@Getter
@Setter
@FieldNameConstants
@NamedEntityGraph(name = "Test", attributeNodes = {@NamedAttributeNode(TestTable.Fields.name)})
@NamedEntityGraph(name = "Test1", attributeNodes = {@NamedAttributeNode(TestTable.Fields.name)})
public class TestTable implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	private Integer id;
	private String name;
	private String value;

}

Using the NamedEntityGraphs Annotation works fine.

@Entity
@Getter
@Setter
@FieldNameConstants
@NamedEntityGraphs({
@NamedEntityGraph(name = "Test", attributeNodes = {@NamedAttributeNode(TestTable.Fields.name)}),
@NamedEntityGraph(name = "Test1", attributeNodes = {@NamedAttributeNode(TestTable.Fields.name)})
})
public class TestTable implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	private Integer id;
	private String name;
	private String value;

}

Is this a known bug ?

@randakar
Copy link

randakar commented Jan 29, 2020 via email

@c-koell
Copy link
Author

c-koell commented Jan 29, 2020

Hi !

Sorry for the unclear description ...

My bug has nothing to do with the NamedEntityGraph Annotation. I have used it to illustrate the problem with
Constants created with the @FieldNameConstants Annotation inside a Repeatable Annotation. https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html

We are using the @FieldNameConstants Annotation to create the Constants for the field names within a Entity Bean.
In the NamedEntityGraph Annotation we are using then that Constants. (See the examples)
@NamedAttributeNode(TestTable.Fields.name)

As described all works fine if we use the Containing Annotation (@NamedEntityGraphs) with the Repeatable Annotations (@NamedEntityGraph)

The Maven compiler finds the created Constants TestTable.Fields.name

If we only use the Repeatable Annotations (@NamedEntityGraph) the Maven compiler will not find the Constants.

We have no problems running the Maven Build with JDK8. After switching to JDK 11 we are getting the described problem.

I hope i have described the problem better :-)

@rzwitserloot
Copy link
Collaborator

I vaguely recall this is actually a known bug. If my recollection is right, then there is not a thing we can do to fix it; javac decides on its own that things cannot possibly work out and will error out before Annotation Processors are invoked at all.

Can you try something? Fully qualify the constant. So, not TestTable.Fields.name, but com.foo.pkg.TestTable.Fields.name. I doubt that's gonna change anything but that is a different bug I recall.

@c-koell
Copy link
Author

c-koell commented Jan 30, 2020

I have tested with the fully qualified package but i have still compile failures.

@rzwitserloot
Copy link
Collaborator

In that case, I am 99.99% certain this is more or less a bug in javac (it's tricky; to make oracle take this bug on and fix it, I need to find a creative way for a normal annotation processor to be able to make this code compilable somehow).

But now I that I think about it, if we make the Fields class a top-level class instead of an inner class (unfortunate; namespace wise this makes so much more sense), that may actually help.

Leaving the bug open for some research, but just to be clear: I expect we're going to be forced to close this issue as 'unfixable'.

@rspilker rspilker changed the title [BUG] Running a Maven compile with Java 11 we get cannot find symbol [BUG] Annotations cannot refer to generated FieldNameConstants Jan 30, 2020
@elingamfelter
Copy link

@rzwitserloot My apologies to comment on an old thread, but has there been any progress on this?

I cannot use the fields generated by @FieldNameConstants in any annotation. Specifically, I have tried to use them in MapStruct and in Jackson annotations and they do not work.

If it helps, am on Java 11.0.13, Gradle 6.9.2, and lombok 1.18.22.

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

No branches or pull requests

4 participants