-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Java: Add synthetic fields; model Commons Lang's MutableObject type #5796
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
Java: Add synthetic fields; model Commons Lang's MutableObject type #5796
Conversation
Not trying to discredit this pull request, it sounds extremely useful for cases where multiple synthetic fields exist, but for |
It actually does add value even with just one field: it enables us to use value flow instead of taint flow. Value flow has to be type-preserving, so we need an Object-typed field, as opposed to the MutableObject or Mutable-typed container. With value flow it's possible to preserve access paths: for example, with taint rules, this example doesn't work:
It doesn't work because taint rules only apply with an empty access path: we can say that if |
* The owning type has no significance except to provide a source location, and to | ||
* aid in avoiding name clashes. | ||
*/ | ||
abstract class SyntheticField extends Unit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether this would work when you have more than one synthetic field - as this class extends unit, it only has one instance; which might just return multiple values for its methods once there are multiple imlementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This observation is spot on. Declaring class SyntheticField extends Unit
means that there's only ever one SyntheticField
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was written back when I thought we identified instances with rows in the charpred table (i.e., with owningType/fieldName tuples), will change...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewritten in the style of the CSV row extension point, and rebased. Ready for re-review.
1764b65
to
9845c27
Compare
javaGenerated file changes for java
- `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,420,,,,,,,,
+ `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,417,,,,,,,,
- Totals,,84,1625,181,13,6,6,,33,1,58
+ Totals,,84,1622,181,13,6,6,,33,1,58
- org.apache.commons.lang3,,,420,,,,,,,,,,,,,,324,96
+ org.apache.commons.lang3,,,417,,,,,,,,,,,,,,324,93 |
javaGenerated file changes for java
- `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,420,,,,,,,,
+ `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,417,,,,,,,,
- Totals,,84,1625,181,13,6,6,,33,1,58
+ Totals,,84,1622,181,13,6,6,,33,1,58
- org.apache.commons.lang3,,,420,,,,,,,,,,,,,,324,96
+ org.apache.commons.lang3,,,417,,,,,,,,,,,,,,324,93 |
^^ Checked, these diffs are reversed. Actually we gained 3 rows, as expected. |
javaGenerated file changes for java
- `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,420,,,,,,,,
+ `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,417,,,,,,,,
- Totals,,84,1625,181,13,6,6,,33,1,58
+ Totals,,84,1622,181,13,6,6,,33,1,58
- org.apache.commons.lang3,,,420,,,,,,,,,,,,,,324,96
+ org.apache.commons.lang3,,,417,,,,,,,,,,,,,,324,93 |
@tamasvajk The action is a bit spammy - is there any way to easily do something about that? E.g. don't post another comment if it already posted an identical comment? |
Hmm, good point. The fix is coming in #6115.
|
@aschackmull this is ready for review |
58a77f5
to
c066e39
Compare
Synthetic field support superseded by #6291 |
c066e39
to
f3d9894
Compare
Rebased. I've kept the improvement to |
javaGenerated file changes for java
- `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,420,,,,,,,,
+ `Apache Commons Lang <https://commons.apache.org/proper/commons-lang/>`_,``org.apache.commons.lang3``,,423,,,,,,,,
- Totals,,84,2109,296,13,6,6,107,33,1,66
+ Totals,,84,2112,296,13,6,6,107,33,1,66
- org.apache.commons.lang3,,,420,,,,,,,,,,,,,,,292,128
+ org.apache.commons.lang3,,,423,,,,,,,,,,,,,,,292,131 |
In fact I have a use case for this kind of thing; in #6174 I have a Table type in which its Rows and Columns are like MapKey so shouldn't be cleared. So far I've been working around it by using things like |
I don't think we should try to include clearing and it also won't work as-is. The reason it won't work is that clearing flow isn't summarised, so if it happens inside a method then callers won't see it happening. And the reason for not summarising clearing flow is that all the calculated flow by the library is existential flow ("there exists at least one path such that"), for which something like setter- and getter-flows can be summarised and incorporated at the call site, but clearing flow is essentially a barrier rather than flow, so it would have to be expressed in terms of universal flow ("for all paths it holds that ..." or "no path exists such that ..."). |
Clearing-as-summary is partially supported by |
Hmm, I see the test does seem to indicate that it actually works... I wonder why that is. I'm not sure it should. |
f3d9894
to
9cde13b
Compare
@aschackmull dropped clearing for synthetic fields. @joefarebrother this means synthetic fields always behave like |
Based on #5772
This adds support for synthetic fields (for now, specifically in external flow specifications), then uses one to model Commons Lang's
MutableObject
type.