Commons Math
  1. Commons Math
  2. MATH-962

Vector3DFormat.parse does not ignore whitespace

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.1
    • Fix Version/s: 3.3
    • Labels:
      None
    • Environment:

      Macosxm, Java 1.6.0

      Description

      Vector3DFormat notes it ingores whitespace in the javadoc but in the below example it does not:
      Vector3DFormat vf = new Vector3DFormat("(", ")", ",");
      System.out.println(vf.parse("(1, 2, 3)")); //prints

      {1; 2; 3}

      System.out.println(vf.parse("(1,2,3)")); //prints null

        Activity

        Leon French created issue -
        Hide
        Thomas Neidhart added a comment -

        This is because internally the number format for the default locale is used in your test-case (without specifying another number format). As in this case grouping is activated (with ',' being the grouping character, e.g. for US locale), the string "1, 2, 3" is interpreted as 123. As there are no other values but 3 are expected, the return value is null.

        To use the Vector3DFormat with ',' as separator, you should explicitly disable grouping like this:

                NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
                nf.setGroupingUsed(false);
                Vector3DFormat vf = new Vector3DFormat("(", ")", ",", nf);
                System.out.println(vf.parse("(1, 2, 3)")); // prints {1; 2; 3}
                System.out.println(vf.parse("(1,2,3)")); // prints null
        

        Afaik, this is one of the reasons why we use ';' as default separator for these vector formats, as this one does not interfere with the usual grouping characters for various locale settings.

        I am not sure this is really a bug, but the error handling could be improved.

        Show
        Thomas Neidhart added a comment - This is because internally the number format for the default locale is used in your test-case (without specifying another number format). As in this case grouping is activated (with ',' being the grouping character, e.g. for US locale), the string "1, 2, 3" is interpreted as 123. As there are no other values but 3 are expected, the return value is null. To use the Vector3DFormat with ',' as separator, you should explicitly disable grouping like this: NumberFormat nf = NumberFormat.getInstance(Locale.getDefault()); nf.setGroupingUsed(false); Vector3DFormat vf = new Vector3DFormat("(", ")", ",", nf); System.out.println(vf.parse("(1, 2, 3)")); // prints {1; 2; 3} System.out.println(vf.parse("(1,2,3)")); // prints null Afaik, this is one of the reasons why we use ';' as default separator for these vector formats, as this one does not interfere with the usual grouping characters for various locale settings. I am not sure this is really a bug, but the error handling could be improved.
        Hide
        Leon French added a comment -

        Oh, I see. Thanks for clearing that up.

        I'm not sure how to make that easier for the next person. A note to the API documentation may help.

        Show
        Leon French added a comment - Oh, I see. Thanks for clearing that up. I'm not sure how to make that easier for the next person. A note to the API documentation may help.
        Hide
        Thomas Neidhart added a comment -

        Added clarification to the javadoc in r1467801.

        Thanks for the report.

        Show
        Thomas Neidhart added a comment - Added clarification to the javadoc in r1467801. Thanks for the report.
        Thomas Neidhart made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 4.0 [ 12317577 ]
        Resolution Fixed [ 1 ]
        Thomas Neidhart made changes -
        Fix Version/s 3.3 [ 12324600 ]
        Fix Version/s 4.0 [ 12317577 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Leon French
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development