[
https://issues.apache.org/jira/browse/TINKERPOP-3306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Cole Greer updated TINKERPOP-3306:
----------------------------------
Priority: Trivial (was: Major)
> SugarLoader `methodMissing` turns misspelled steps and wrong-type calls into
> `values()`
> ---------------------------------------------------------------------------------------
>
> Key: TINKERPOP-3306
> URL: https://issues.apache.org/jira/browse/TINKERPOP-3306
> Project: TinkerPop
> Issue Type: Bug
> Components: console
> Affects Versions: 3.7.7, 3.8.2
> Reporter: Cole Greer
> Priority: Trivial
>
> {{SugarLoader}} adds this catch-all to {{GraphTraversal}} so that property
> access like {{g.V().age}} works:
> {code:groovy}
> //
> gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoader.groovy
> GraphTraversal.metaClass.methodMissing = { final String name, final def args
> ->
> return ((GraphTraversal) delegate).values(name);
> }
> {code}
> The closure ignores {{args}}. Groovy calls it for every method call it can't
> resolve, so a typo or an argument type that matches no overload doesn't raise
> an error. The call becomes {{values(<methodName>)}}, the arguments are thrown
> away, and the traversal usually returns an empty result. The user gets no
> sign that anything went wrong.
> Reproduce in the Gremlin Console with {{TinkerFactory.createModern()}}:
> {code:groovy}
> gremlin> g.V().hasLabl('person') // misspelled hasLabel
> // compiles to g.V().values("hasLabl") -> []
> gremlin> g.V().outE('knows').inv() // misspelled inV
> // compiles to g.V().outE("knows").values("inv") -> []
> gremlin> g.V().limit('2') // String where a long is expected
> // compiles to g.V().values("limit") -> []
> {code}
> *Expected:* a {{MissingMethodException}}, which is what you get without the
> sugar plugin, or with the grammar, where these are parse errors.
> *Proposed fix:* use the {{values(name)}} fallback only when {{args}} is
> empty, which is the property-access case it exists for. Otherwise throw {{new
> MissingMethodException(name, delegate.getClass(), args)}}. {{g.V().age}}
> keeps working, and calls with arguments that match no step fail loudly. The
> fix needs a test showing that {{g.V().age}} still compiles to
> {{values("age")}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)