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

Fix "reference to Record is ambiguous" build error on JDK 16 and above #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Leo3418
Copy link

@Leo3418 Leo3418 commented Apr 4, 2022

The commit in this pull request fixes compiler errors like the following one when this project is being built using JDK 16 or above:

src/main/java/com/univocity/parsers/common/Context.java:136: error: reference to Record is ambiguous
        Record toRecord(String[] row);
        ^
  both interface com.univocity.parsers.common.record.Record in com.univocity.parsers.common.record and class java.lang.Record in java.lang match

More details are explained in the commit message.

Although this project's pom.xml still declares Java 1.6 as the compilation source/target, which means that it cannot be built using JDK 12+ yet, this change would still make this project more future-proof under all circumstances. It eliminates one issue you folks would encounter when you decide to support JDK 17 for the latest LTS release of Java. Even if you wish to stay on older Java versions for an extended period, this commit is backward-compatible with older JDK versions and does not introduce any regression both theoretically and practically according to my testing.

For what it is worth, the aforementioned compiler errors were discovered when we packaged this project for a GNU/Linux distribution (Leo3418/junit-5-ebuild-repo#4). We, as distribution maintainers, often use a more up-to-date version of JDK to build packages for various Java projects:

Therefore, we, as maintainers of those distributions, would appreciate your attention to support for the newer JDK versions.

Since Java 16, a new java.lang.Record class has been added to the Java
SE API.  Classes under the java.lang package, including this Record
class, are automatically imported in any Java source file.  Because this
project also has a com.univocity.parsers.common.record.Record interface,
when it is being compiled on JDK 16 and above, there would be an
ambiguity as to which class/interface to use for the 'Record' type:

src/main/java/com/univocity/parsers/common/Context.java:136: error: reference to Record is ambiguous
        Record toRecord(String[] row);
        ^
  both interface com.univocity.parsers.common.record.Record in com.univocity.parsers.common.record and class java.lang.Record in java.lang match

The resolution to this issue is simply to import the Record interface
under this project explicitly in every source file using it.

Bug: Leo3418/junit-5-ebuild-repo#4
Reported-by: Volkmar W. Pogatzki <[email protected]>
Signed-off-by: Yuan Liao <[email protected]>
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

Successfully merging this pull request may close these issues.

1 participant