jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1378184 - in /jena/trunk/jena-tdb/src: main/java/com/hp/hpl/jena/tdb/store/NodeId.java test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
Date Tue, 28 Aug 2012 15:45:32 GMT
Author: andy
Date: Tue Aug 28 15:45:31 2012
New Revision: 1378184

URL: http://svn.apache.org/viewvc?rev=1378184&view=rev
Log:
Hanlde out-of-range derived integers and very, very large integers (>63 bits).

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java?rev=1378184&r1=1378183&r2=1378184&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/NodeId.java Tue Aug 28 15:45:31
2012
@@ -207,13 +207,25 @@ public class NodeId
         {
             if ( XSDDatatype.XSDinteger.isValidLiteral(lit) )
             {
-                long v = ((Number)lit.getValue()).longValue() ;
-                v = IntegerNode.pack(v) ;
-                // Value -1 is "does not fit"
-                if ( v != -1 )
-                    return new NodeId(v) ;
-                else
+                // Check length of lexical form to see if it's in range of a long.
+                // Long.MAX_VALUE =  9223372036854775807
+                // Long.MIN_VALUE = -9223372036854775808
+                // 9,223,372,036,854,775,807 is 19 digits.
+                
+                if ( lit.getLexicalForm().length() > 19 )
                     return null ;
+
+                try {
+                    long v = ((Number)lit.getValue()).longValue() ;
+                    v = IntegerNode.pack(v) ;
+                    // Value -1 is "does not fit"
+                    if ( v != -1 )
+                        return new NodeId(v) ;
+                    else
+                        return null ;
+                }
+                // Out of range for the type, not a long etc etc.
+                catch (Throwable ex) { return null ; }
             }
         }
         
@@ -292,11 +304,6 @@ public class NodeId
             case INTEGER:
             {
                 long val = IntegerNode.unpack(v) ;
-//                
-//                long val = BitsLong.clear(v, 56, 64) ;
-//                // Sign extends to 64 bits.
-//                if ( BitsLong.isSet(val, 55) )
-//                    val = BitsLong.set(v, 56, 64) ;
                 Node n = Node.createLiteral(Long.toString(val), null, XSDDatatype.XSDinteger)
;
                 return n ;
             }

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java?rev=1378184&r1=1378183&r2=1378184&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestNodeId.java Tue Aug 28
15:45:31 2012
@@ -41,30 +41,37 @@ public class TestNodeId extends BaseTest
     
     // Inlines
     
-    @Test public void nodeId_int_1()
+    @Test public void nodeId_int_01()
     { test("1", NodeFactory.parseNode("1")) ; }
 
-    @Test public void nodeId_int_2()
+    @Test public void nodeId_int_02()
     { test("2", NodeFactory.parseNode("2")) ; }
 
-    @Test public void nodeId_int_3()
+    @Test public void nodeId_int_03()
     { test("'3'^^xsd:int", NodeFactory.parseNode("3")) ; }
 
-    @Test public void nodeId_int_4()
+    @Test public void nodeId_int_04()
     { test("'3'", (Node)null) ; }
 
-    @Test public void nodeId_int_5()
+    @Test public void nodeId_int_05()
     { test("-1",  NodeFactory.parseNode("-1")) ; }
     
-    @Test public void nodeId_int_6()
+    @Test public void nodeId_int_06()
     { test("-180",  NodeFactory.parseNode("-180")) ; }
 
-    @Test public void nodeId_int_7()
+    @Test public void nodeId_int_07()
     { test("01",  NodeFactory.parseNode("1")) ; }
     
-    @Test public void nodeId_int_8()
+    @Test public void nodeId_int_08()
     { test("+01",  NodeFactory.parseNode("1")) ; }
     
+    @Test public void nodeId_int_09()
+    // More than Long.MAX_VALUE
+    { test("92233720368547758070",  (Node)null) ; }
+
+    @Test public void nodeId_int_10()
+    { test("'300'^^xsd:byte",  (Node)null) ; }
+    
     @Test public void nodeId_decimal_1()
     { test("3.14", NodeFactory.parseNode("3.14")) ; }
 



Mime
View raw message