Skip to content

Add filter for Records #990

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

Merged
merged 4 commits into from
Jan 7, 2020
Merged

Add filter for Records #990

merged 4 commits into from
Jan 7, 2020

Conversation

Godin
Copy link
Member

@Godin Godin commented Jan 6, 2020

I propose to filter methods toString, hashCode and equals that compiler generates for Records (JEP 359), leaving accessor methods untouched, which is consistent with what we do for Kotlin data classes.


For

record Point(int x, int y) {
    public static void main(String[] args) {
        new Point(0, 0);
    }
}

Using java -version

openjdk version "14-ea" 2020-03-17
OpenJDK Runtime Environment (build 14-ea+30-1385)
OpenJDK 64-Bit Server VM (build 14-ea+30-1385, mixed mode, sharing)
javac \
    --enable-preview \
    --release 14 \
    -d classes \
    Point.java

java \
    --enable-preview \
    -javaagent:jacocoagent.jar \
    -cp classes \
    Point

Generation of report

java -jar jacococli.jar \
    report jacoco.exec \
    --classfiles classes \
    --sourcefiles src \
    --html report

before this change produces

before

and after

after

@Godin Godin requested a review from marchof January 6, 2020 19:14
@marchof marchof merged commit fbd0099 into master Jan 7, 2020
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
Copy link
Member

@marchof marchof Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: Why does surefire require this flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marchof enablement of Preview Features by --enable-preview flag is required both at compile and at run time - see Preview Language and VM Features (JEP 12), otherwise we'll get

java.lang.UnsupportedClassVersionError: Preview features are not enabled for org/jacoco/core/test/validation/java14/RecordsTest (class file version 58.65535). Try running with '--enable-preview'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks!

@marchof marchof deleted the java14_records branch January 7, 2020 09:27
@Godin Godin added this to the 0.8.6 milestone Jan 7, 2020
@ice1000
Copy link
Contributor

ice1000 commented Oct 4, 2021

Should we also ignore the accessors?

@ice1000
Copy link
Contributor

ice1000 commented Oct 4, 2021

See #1215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants