4

I have a Java 8 application with I want to bring to Java 11. The Gradle 5.0 build contains a dependency to JFreeChart 1.5.0 and JAVA_HOME is set to the installed jdk-11.0.1 from Oracle. When building a get the following output:

> Task :nemclient:compileJava
error: clone() in AbstractXYItemRenderer cannot implement clone() in PublicCloneable
attempting to assign weaker access privileges; was public

The class AbstractXYItemRenderer is provided by the JFreeChart library. There are two questions:

  • Why does the build complain after all? Since I don't assume that Gradle tries to build the library (the library source is not provided here), what causes this error?
  • An analysis of the library source shows, that the class AbstractXYItemRenderer doesn't implement the PublicClone interface at all, neither directly nor indirectly.

The error disappears, when the modifier of the clone method is changed from protected to public. But I'd prefer to leave the code unchanged.

BTW: The same project in Eclipse (using Java 11 plugin and the mentioned jdk-11.0.1) has no compile issue.

paedu
  • 41
  • 1
  • When you say the build fails, how do you run your build? From command line? With gradle or gradlew? Can you specify? If you run the same gradle version in terminal and IDE, there shouldn't be any difference. – José Pereda Dec 11 '18 at 16:31
  • JFreeChart contains two interfaces. One declares `clone()` as `protected` and one as `public`. It seems like Java 11 considers the interface implementation hierarchy/order which ends up that first the one interface declares that `clone`has to be public and the the other interface wants to make it protected. Previous Java versions ignored this declaration conflict. – Robert Dec 12 '18 at 13:22
  • I run the build from the command line using gradlew. In Eclipse I don't refer to the Gradle project, instead I build the Eclipse project, which I generate with gradlew eclipse. – paedu Dec 12 '18 at 18:19
  • What concerns the interfaces, the one provided by the library is called PublicClone (defining a public clone() method), while the other is called Clone and comes with Java since version 1.0. As said, the class AbstractXYItemRenderer doesn't implement the PublicClone interface at all, rather it overrides the protected clone() method inherited from Object. – paedu Dec 12 '18 at 18:27
  • Interestingly, most other renderers implement both `Cloneable` and `PublicCloneable`. – trashgod Dec 13 '18 at 16:54

0 Answers0