Commons Math
  1. Commons Math
  2. MATH-988

NPE when calling SubLine.intersection() with non-intersecting lines

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0, 3.1, 3.2, 3.1.1
    • Fix Version/s: 3.3
    • Labels:
      None

      Description

      When calling SubLine.intersection() with two lines that not intersect, then a NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod and threed implementations.

      The attached patch fixes both implementations and adds the required test cases.

        Activity

        Andreas Huber created issue -
        Andreas Huber made changes -
        Field Original Value New Value
        Attachment SubLineIntersection.patch [ 12585757 ]
        Andreas Huber made changes -
        Description When calling SubLine.intersection() with two lines that not intersect, then a NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod and threed implementations.

        The following patch fixes both implementations and adds the required test cases:

        Index: src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
        ===================================================================
        --- src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java (revision 1488671)
        +++ src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java (working copy)
        @@ -152,5 +152,13 @@
                 Assert.assertNull(sub1.intersection(sub2, true));
                 Assert.assertNull(sub1.intersection(sub2, false));
             }
        +
        + @Test
        + public void testIntersectionNotIntersecting() throws MathIllegalArgumentException {
        + SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(1.5, 1, 1));
        + SubLine sub2 = new SubLine(new Vector3D(2, 3, 0), new Vector3D(2, 3, 0.5));
        + Assert.assertNull(sub1.intersection(sub2, true));
        + Assert.assertNull(sub1.intersection(sub2, false));
        + }
         
         }
        Index: src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java
        ===================================================================
        --- src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java (revision 1488671)
        +++ src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java (working copy)
        @@ -144,4 +144,12 @@
                 Assert.assertNull(sub1.intersection(sub2, false));
             }
         
        + @Test
        + public void testIntersectionParallel()
        + {
        + final SubLine sub1 = new SubLine(new Vector2D(0, 1), new Vector2D(0, 2));
        + final SubLine sub2 = new SubLine(new Vector2D(66, 3), new Vector2D(66, 4));
        + Assert.assertNull(sub1.intersection(sub2, true));
        + Assert.assertNull(sub1.intersection(sub2, false));
        + }
         }
        Index: src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
        ===================================================================
        --- src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java (revision 1488671)
        +++ src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java (working copy)
        @@ -111,6 +111,10 @@
         
                 // compute the intersection on infinite line
                 Vector3D v1D = line.intersection(subLine.line);
        + if (v1D == null)
        + {
        + return null;
        + }
         
                 // check location of point with respect to first sub-line
                 Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));
        Index: src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
        ===================================================================
        --- src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java (revision 1488671)
        +++ src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java (working copy)
        @@ -115,6 +115,10 @@
         
                 // compute the intersection on infinite line
                 Vector2D v2D = line1.intersection(line2);
        + if (v2D == null)
        + {
        + return null;
        + }
         
                 // check location of point with respect to first sub-line
                 Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));


        When calling SubLine.intersection() with two lines that not intersect, then a NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod and threed implementations.

        The attached patch fixes both implementations and adds the required test cases.

        Luc Maisonobe made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Thomas Neidhart made changes -
        Fix Version/s 3.3 [ 12324600 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Andreas Huber
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development