Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: jscience-issues
Reporter: cheremin
Votes: 1
Watchers: 0

If you were logged in you would be able to see more operations.

NPE in Unit.alternate

Created: 04/Feb/08 02:55 AM   Updated: 31/Jan/11 02:49 AM
Component/s: www
Affects Version/s: current
Fix Version/s: Version 6.0

Time Tracking:
Not Specified


Operating System: All
Platform: All

Issuezilla Id: 86
Participants: cheremin and jscience-issues

 Description  « Hide

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

at javax.measure.unit.AlternateUnit.hashCode(
at java.util.HashMap.get(
at javax.measure.unit.UnitFormat$DefaultFormat.nameFor(
at javax.measure.unit.UnitFormat$DefaultFormat.format(
at javax.measure.unit.UnitFormat.format(
at java.text.Format.format(
at javax.measure.unit.Unit.toString(
at java.lang.String.valueOf(
at java.lang.StringBuilder.append(
at javax.measure.unit.AlternateUnit.<init>(
at javax.measure.unit.Unit.alternate(

There are no comments yet on this issue.