You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/06/20 19:29:13 UTC

[tinkerpop] branch master updated (a52a8cc -> 24cd564)

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git.


    from a52a8cc  Merge branch 'tp34'
     new dcf9e07  TINKERPOP-2236 Improve error messaging for IdManager CTR
     new e8de6e9  Merge branch 'tp33' into tp34
     new 24cd564  Merge branch 'tp34'

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.asciidoc                                 |  1 +
 .../gremlin/tinkergraph/structure/TinkerGraph.java | 38 +++++++---
 .../tinkergraph/structure/IdManagerTest.java       | 81 ++++++++++++++++++++++
 3 files changed, 110 insertions(+), 10 deletions(-)
 create mode 100644 tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IdManagerTest.java


[tinkerpop] 03/03: Merge branch 'tp34'

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 24cd5640c806cda23170662203e689dfc0ee3f3f
Merge: a52a8cc e8de6e9
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Thu Jun 20 15:29:00 2019 -0400

    Merge branch 'tp34'

 CHANGELOG.asciidoc                                 |  1 +
 .../gremlin/tinkergraph/structure/TinkerGraph.java | 38 +++++++---
 .../tinkergraph/structure/IdManagerTest.java       | 81 ++++++++++++++++++++++
 3 files changed, 110 insertions(+), 10 deletions(-)



[tinkerpop] 02/03: Merge branch 'tp33' into tp34

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit e8de6e9fec6e457de7fc603325aff820b5f07c12
Merge: 922934b dcf9e07
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Thu Jun 20 15:19:34 2019 -0400

    Merge branch 'tp33' into tp34

 CHANGELOG.asciidoc                                 |  1 +
 .../gremlin/tinkergraph/structure/TinkerGraph.java | 38 +++++++---
 .../tinkergraph/structure/IdManagerTest.java       | 81 ++++++++++++++++++++++
 3 files changed, 110 insertions(+), 10 deletions(-)



[tinkerpop] 01/03: TINKERPOP-2236 Improve error messaging for IdManager CTR

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit dcf9e070eac6cce7bd651c22059ecd8738f692d5
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Thu Jun 20 15:08:59 2019 -0400

    TINKERPOP-2236 Improve error messaging for IdManager CTR
---
 CHANGELOG.asciidoc                                 |  1 +
 .../gremlin/tinkergraph/structure/TinkerGraph.java | 38 +++++++---
 .../tinkergraph/structure/IdManagerTest.java       | 81 ++++++++++++++++++++++
 3 files changed, 110 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e60b668..632e8d5 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -29,6 +29,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Improved exception and messaging for gt/gte/lt/lte when one of the object isn't a `Comparable`.
 * Added test infrastructure to check for storage iterator leak.
 * Fixed multiple iterator leaks in query processor.
+* Improved error messaging for invalid inputs to the TinkerGraph `IdManager` instances.
 * Changed the `reverse()` of `desc` and `asc` on `Order` to not use the deprecated `decr` and `incr`.
 * Fixed bug in `MatchStep` where the correct was not properly determined.
 * Fixed bug where client/server exception mismatch when server throw StackOverflowError
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index 5167e01..09a5584 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -581,10 +581,15 @@ public final class TinkerGraph implements Graph {
                     return id;
                 else if (id instanceof Number)
                     return ((Number) id).longValue();
-                else if (id instanceof String)
-                    return Long.parseLong((String) id);
+                else if (id instanceof String) {
+                    try {
+                        return Long.parseLong((String) id);
+                    } catch (NumberFormatException nfe) {
+                        throw new IllegalArgumentException(createErrorMessage(Long.class, id));
+                    }
+                }
                 else
-                    throw new IllegalArgumentException(String.format("Expected an id that is convertible to Long but received %s", id.getClass()));
+                    throw new IllegalArgumentException(createErrorMessage(Long.class, id));
             }
 
             @Override
@@ -611,10 +616,15 @@ public final class TinkerGraph implements Graph {
                     return id;
                 else if (id instanceof Number)
                     return ((Number) id).intValue();
-                else if (id instanceof String)
-                    return Integer.parseInt((String) id);
+                else if (id instanceof String) {
+                    try {
+                        return Integer.parseInt((String) id);
+                    } catch (NumberFormatException nfe) {
+                        throw new IllegalArgumentException(createErrorMessage(Integer.class, id));
+                    }
+                }
                 else
-                    throw new IllegalArgumentException(String.format("Expected an id that is convertible to Integer but received %s", id.getClass()));
+                    throw new IllegalArgumentException(createErrorMessage(Integer.class, id));
             }
 
             @Override
@@ -639,10 +649,14 @@ public final class TinkerGraph implements Graph {
                     return null;
                 else if (id instanceof java.util.UUID)
                     return id;
-                else if (id instanceof String)
-                    return java.util.UUID.fromString((String) id);
-                else
-                    throw new IllegalArgumentException(String.format("Expected an id that is convertible to UUID but received %s", id.getClass()));
+                else  if (id instanceof String) {
+                    try {
+                        return java.util.UUID.fromString((String) id);
+                    } catch (IllegalArgumentException iae) {
+                        throw new IllegalArgumentException(createErrorMessage(java.util.UUID.class, id));
+                    }
+                } else
+                    throw new IllegalArgumentException(createErrorMessage(java.util.UUID.class, id));
             }
 
             @Override
@@ -672,6 +686,10 @@ public final class TinkerGraph implements Graph {
             public boolean allow(final Object id) {
                 return true;
             }
+        };
+
+        private static String createErrorMessage(final Class<?> expectedType, final Object id) {
+            return String.format("Expected an id that is convertible to %s but received %s - [%s]", expectedType, id.getClass(), id);
         }
     }
 }
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IdManagerTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IdManagerTest.java
new file mode 100644
index 0000000..e9fe77e
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IdManagerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.tinkergraph.structure;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.UUID;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IdManagerTest {
+    @Rule
+    public ExpectedException exceptionRule = ExpectedException.none();
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfStringToInt() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.INTEGER;
+        manager.convert("string-id");
+    }
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfJunkToInt() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.INTEGER;
+        manager.convert(UUID.randomUUID());
+    }
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfStringToLong() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.LONG;
+        manager.convert("string-id");
+    }
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfJunkToLong() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.LONG;
+        manager.convert(UUID.randomUUID());
+    }
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfStringToUUID() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.UUID;
+        manager.convert("string-id");
+    }
+
+    @Test
+    public void shouldGenerateNiceErrorOnConversionOfJunkToUUID() {
+        exceptionRule.expect(IllegalArgumentException.class);
+        exceptionRule.expectMessage("Expected an id that is convertible to");
+        final TinkerGraph.IdManager manager = TinkerGraph.DefaultIdManager.UUID;
+        manager.convert(Double.NaN);
+    }
+}