-
-
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
Weird behavior (with "own" ProductUnit?) #353
Comments
@fawidmer Thanks for raising this, what keeps you from upgrading to Indriya 2.1.x?
Are you redeclaring or using
No, while the constructor currently is open and public you should not use it because it's entirely for use by the ONE constant. ICU4J makes a distinciton between MeasureUnit and NoUnit in recent versions and I guess if we decided to go in a similar direction, we could (with a grace period and deprecating the existing constants) introduce a similar smaller SystemOfUnits implementations like |
Thank you very much @keilw for the detailed feedback!
import javax.measure.Unit;
import javax.measure.quantity.Volume;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tech.units.indriya.unit.Units;
import tech.uom.lib.jackson.UnitJacksonModule;
/**
* @author fawidmer
*/
public class Temp {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mpr = new ObjectMapper();
mpr.registerModule(new UnitJacksonModule());
Unit<Volume> value = Units.CUBIC_METRE;
String content = mpr.writeValueAsString(value);
Unit readValue = mpr.readValue(content, Unit.class);
}
} Error trace:
|
@fawidmer Can this also be closed similar to unitsofmeasurement/uom-lib#68 or is there a separate issue left here? |
Dear @keilw
I will come back to you if it persists, ok? |
Ok thanks @fawidmer please verify and if it works now you can close the ticket you created yourself. |
Hello everyone
We are using indriya (v2.0.4) in a multi-thread environment. As I already pointed out a while back in #284, we have been facing some weird erratic behavior, which we were not able to reproduce. So we figured it might be some concurrency issue.
Unfortunately, we discovered recently, that the pull request above did not resolve our issues. Maybe, you have some ideas on how we could approach our issues or where they might come from.
Some info on what we're doing:
We have an own implementation of a "quantity", which consists basically of a java
double
and ajavax.measure.Unit
.We have in a class a static field which we use for all of our dimensionless quantities:
public static final Unit<Dimensionless> ONE = new ProductUnit<Dimensionless>();
See the attached file: Units.txtBefore starting our various threads, we are initializing some parameter objects in our main thread, (we are using reflections to call the respective constructors, don't know if that's of important). These parameters contain many different quantities.
After that, we start up various threads, some of which read (quantity) values from JSON files.
We have observed the following weird behavior:
X
(from JSON) resulted in a value of1.8749687871307178E9
with unitONE
, although the JSON raw content was0.0
with unitONE
.Y
, which is hard-coded as0.95
with the unitONE
, was somehow converted again to a value of1.8749687871307178E9
with unitONE
.X
was again read from JSON. The raw value of1.8749687871307178E9
with unitONE
was then strangely parsed as0.98
with the unitONE
.Units.OHM
, where a value of 0.2 was suddenly converted to~9.5557e+08
once, and~9.8284e+08
another time...Questions:
1.8749687871307178E9
might come from? Or in general, the numbers of approximate size 1E9?ProductUnit
constructor like that? We are not adding the unit to any of the (hash)sets in any instance ofAbstractSystemOfUnits
. Is that a problem?Thank you for any form of help, it is much appreciated!
Fabio
The text was updated successfully, but these errors were encountered: