-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreign Units must be handled with no Surprises #209
Comments
waiting on #204 to be resolved/merged |
There are a few cases which assume |
For example when looking at @Override
public UnitConverter getSystemConverter() {
UnitConverter converter = AbstractConverter.IDENTITY;
for (Element e : elements) {
if (e.unit instanceof AbstractUnit) {
UnitConverter cvtr = ((AbstractUnit<?>) e.unit).getSystemConverter();
if (!(cvtr.isLinear()))
throw new UnsupportedOperationException(e.unit + " is non-linear, cannot convert");
if (e.root != 1)
throw new UnsupportedOperationException(e.unit + " holds a base unit with fractional exponent");
int pow = e.pow;
if (pow < 0) { // Negative power.
pow = -pow;
cvtr = cvtr.inverse();
}
for (int j = 0; j < pow; j++) {
converter = converter.concatenate(cvtr);
}
}
}
return converter;
} If the ProductUnit contains an element that is not an instance of AbstractUnit, we still return a converter, but we should instead fail, I guess! I believe we have multiple such code fragments that do not behave well, when 'foreign' Units are used. |
As an alternative to failing with exceptions, we could instead within RI lookout for places that allow to replace/narrow method arguments |
This may not work in every case, but here the logical solution would be offering |
Several code fragments assume that any Unit is an (or a subtype of)
AbstractUnit
.This might result in
ClassCastException
s, when instead we should throw a proper and more descriptiveUnsupportedOperationException
.Some code-paths are simply ignored, when a Unit is not of type
AbstractUnit
. Its critical to make sure, we properly throw anUnsupportedOperationException
instead, to prevent users from running into incorrect calculations. (Calculations must fail instead!)The text was updated successfully, but these errors were encountered: