Github user dkuppitz commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/342#discussion_r67415317
  
    --- Diff: 
tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
 ---
    @@ -358,6 +350,14 @@ public Features features() {
             return features;
         }
     
    +    private void validateHomogenousIds(final List<Object> ids) {
    +        final Class firstClass = ids.get(0).getClass();
    +        for (Object id : ids) {
    +            if (!id.getClass().equals(firstClass))
    +                throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
    +        }
    +    }
    +
    --- End diff --
    
    This opens the door for NPE's.
    
    ```
    gremlin> graph.vertices("a", null, 1)
    java.lang.NullPointerException
    Display stack trace? [yN] y
    java.lang.NullPointerException
        at 
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.validateHomogenousIds(TinkerGraph.java:356)
        at 
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.createElementIterator(TinkerGraph.java:329)
        at 
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.vertices(TinkerGraph.java:269)
    ```
    
    Suggestion with a few tweaks:
    
    ```
    private void validateHomogenousIds(final List<Object> ids) {
        final Iterator<Object> iterator = ids.iterator();
        Object id = iterator.next();
        if (id == null)
            throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
        final Class firstClass = id.getClass();
        while (iterator.hasNext()) {
            id = iterator.next();
            if (id == null || !id.getClass().equals(firstClass))
                throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
        }
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to