[
https://issues.apache.org/jira/browse/TINKERPOP-3306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18145795#comment-18145795
]
ASF GitHub Bot commented on TINKERPOP-3306:
-------------------------------------------
spmallette opened a new pull request, #3811:
URL: https://github.com/apache/tinkerpop/pull/3811
A call on a GraphTraversal that has arguments but matches no step, such as a
misspelled hasLabl('person') or limit('2'), now throws MissingMethodException
instead of silently becoming values(name). g.V().age and g.V().age() still
resolve to values('age').
Assisted-by: Claude Code:claude-opus-5-5
<!--
Thanks for contributing! Reminders:
+ TARGET the earliest branch where you want the change
3.7-dev -> 3.7.7 (non-breaking only)
3.8-dev -> 3.8.2 (non-breaking only)
master -> 4.0.0
+ Committers will MERGE the PR forward to newer versions
+ ADD entry to the CHANGELOG.asciidoc for the targeted version
Do not reference a JIRA number there
+ ADD JIRA number to title and link in description
+ PRs requires 3 +1s from committers OR
1 +1 and 7 day wait to merge.
+ MORE details: https://s.apache.org/rtnal
-->
> 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)