Skip to content

Conversation

@aschackmull
Copy link
Contributor

This adds support for flow through Java 14 records.

@aschackmull aschackmull requested a review from a team as a code owner August 24, 2020 09:52
recf.getDeclaringType() = r and
getter.getNumberOfParameters() = 0 and
getter.getName() = recf.getName() and
not exists(getter.getBody()) and
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose abstract records are not allowed, so checking for the absence of a body is fine, however, wouldn't it be better to use getter.fromSource() instead

Copy link
Contributor Author

@aschackmull aschackmull Aug 31, 2020

Choose a reason for hiding this comment

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

Records are implicitly final and therefore can't be abstract. It looks like checking fromSource() would work as well, but I didn't expect it based on the qldoc of fromSource() - it states:

   * Holds if this element pertains to a source file.
   *
   * Elements pertaining to source files may include generated elements
   * not visible in source code, such as implicit default constructors.

So I would actually expect fromSource() to hold for a generated getter when the corresponding record is fromSource(). I wonder why that isn't the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, sounds like it's best to keep using the empty body check.

@@ -0,0 +1,28 @@
public class A {
record Pair(Object x, Object y) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add some test with fields that have explicit "get" methods? I think one field with a sensible get method that just returns the field (has flow) and one silly get method that returns a constant (no flow)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks good to me. Could you add some more tests and perhaps use fromSource()?

@aibaars aibaars merged commit 2729d10 into github:main Sep 1, 2020
@aschackmull aschackmull deleted the java/records-dataflow branch September 1, 2020 11:03
aschackmull added a commit to aschackmull/ql that referenced this pull request Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants