-
Notifications
You must be signed in to change notification settings - Fork 841
Fix JavaTranslator's has handling for null arguments
#3274
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
base: 3.8-dev
Are you sure you want to change the base?
Conversation
- Updated `has()` special case logic to address potential issues when first or third arguments are `null`. Example : `g.E().has("knows","weight",null)` this query can lead to NPE on server execution as JavaTranslator can choose GraphTravers#has(String, Sring, P) method instead of GraphTravers#has(String, Sring, Object)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.8-dev #3274 +/- ##
==========================================
Coverage ? 77.29%
Complexity ? 15015
==========================================
Files ? 1159
Lines ? 71926
Branches ? 8025
==========================================
Hits ? 55596
Misses ? 13277
Partials ? 3053 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
It would be good to add a unit test for this. Here is a suggested one since there are no existing (direct) unit tests for the |
| import org.apache.tinkerpop.gremlin.process.traversal.Translator; | ||
| import org.apache.tinkerpop.gremlin.process.traversal.Traversal; | ||
| import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; | ||
| import org.apache.tinkerpop.gremlin.process.traversal.*; |
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.
It looks like your IDE has auto style formatting which differs from the conventions used in the tinkerpop project and thus the wildcard import has been added and various whitespace changes as well. According to https://tinkerpop.apache.org/docs/current/dev/developer/#_code_style we try to keep the style consistent with the existing conventions.
Contributors should examine the current code base to determine what the code style patterns are and should match their style to what is already present. Of specific note however, TinkerPop does not use "import wildcards" - IDEs should be adjusted accordingly to not auto-wildcard the imports.
| } else if (newArguments.length == 3 && newArguments[2] == null && parametersTypes[0] == String.class && | ||
| parametersTypes[1] == String.class && | ||
| parametersTypes[2] == P.class) { | ||
| //the second case has(String, String, (P)(null)) instead of has(String,String, (Object)null) | ||
| found = false; | ||
| } |
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 surprised the has overloads with 2 method args have not also surfaced also a problem (it could just be by luck depending on the order of the methods loaded in the global cache). You could change the logic to address both the 2 and 3 arg method overloads:
| } else if (newArguments.length == 3 && newArguments[2] == null && parametersTypes[0] == String.class && | |
| parametersTypes[1] == String.class && | |
| parametersTypes[2] == P.class) { | |
| //the second case has(String, String, (P)(null)) instead of has(String,String, (Object)null) | |
| found = false; | |
| } | |
| } else if (newArguments[newArguments.length - 1] == null && parametersTypes[newArguments.length - 1] == P.class) { | |
| //the second case has(String, String, (P)(null)) instead of has(String,String, (Object)null) | |
| //or has(String, (P)(null)) instead of has(String, (Object)null) | |
| found = false; | |
| } |
|
Hi. The correct fix is to sort the list of methods during the building method cache by isAssigned from the relationship. That will fix all current and future problems. |
|
Hi @andrii0lomakin I opened #3278 because I wanted a fix for the issue you found in 3.8.0 for which the release vote is happening today which unfortunately doesn't give you enough time to refactor the change as you mentioned. Please do continue with this PR and it can be added to 3.8.1 or 4.0. Thanks! |
has()special case logic to address potential issues when first or third arguments arenull. Example :g.E().has("knows","weight",null)this query can lead to NPE on server execution as JavaTranslator can choose GraphTravers#has(String, Sring, P) method instead of GraphTravers#has(String, Sring, Object)