Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      86

      Description

      When I try to create alternate unit for non-standart one, I've got NPE instead
      of supposed IllegalArgumentException, of something like it.

      Test case:

      final Unit<Duration> minute = SI.SECOND.times( 60 );
      minute.alternate("minute"); //here i've got NPE

      Browsing sources I found the reason:

      AlternateUnit(String symbol, Unit<?> parent) {
      if (!parent.isStandardUnit())
      throw new UnsupportedOperationException(this
      + " is not a standard unit");

      it's quote from AlternateUnit constructor. When parent is non-standart unit, it
      throws UnsupportedOperationException, but during evaluation of this
      + " is not a standard unit" we've got NPE from this.toString() (since this
      currently is not valid – all fields are null). Here is the stack trace

      java.lang.NullPointerException
      at javax.measure.unit.AlternateUnit.hashCode(AlternateUnit.java:122)
      at java.util.HashMap.get(HashMap.java:343)
      at javax.measure.unit.UnitFormat$DefaultFormat.nameFor(UnitFormat.java:305)
      at javax.measure.unit.UnitFormat$DefaultFormat.format(UnitFormat.java:639)
      at javax.measure.unit.UnitFormat.format(UnitFormat.java:187)
      at java.text.Format.format(Format.java:133)
      at javax.measure.unit.Unit.toString(Unit.java:499)
      at java.lang.String.valueOf(String.java:2615)
      at java.lang.StringBuilder.append(StringBuilder.java:116)
      at javax.measure.unit.AlternateUnit.<init>(AlternateUnit.java:50)
      at javax.measure.unit.Unit.alternate(Unit.java:299)

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jscience-issues
            Reporter:
            cheremin
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: