OpenPojo / openpojo

POJO Testing & Identity Management Made Trivial
http://openpojo.com
Apache License 2.0
156 stars 40 forks source link

DateTimeException #96

Closed sixcorners closed 7 years ago

sixcorners commented 7 years ago
16:41:31.581 [main] DEBUG com.openpojo.random.impl.DefaultRandomGenerator - Creating basic instance for type=[class java.time.Instant] using InstanceFactory

java.time.DateTimeException: Invalid value for NanoOfSecond (valid values 0 - 999999999): -842099582

...
at java.time.Instant.toString(Instant.java:1330)
at com.openpojo.log.utils.MessageFormatter.format(MessageFormatter.java:131)
...

This tool seems to create an invalid Instant depending on a random value then later when it tries to toString it an exception is thrown.

Is this something that should be an issue here?

Here is the random generator I'm using to fix this:

@BeforeClass
public static void init() {
    RandomFactory.addRandomGenerator(new RandomGenerator() {
        @Override
        public Collection<Class<?>> getTypes() {
            return Collections.singletonList(Instant.class);
        }

        @Override
        public Object doGenerate(Class<?> type) {
            return Instant.ofEpochMilli(ThreadLocalRandom.current().nextLong());
        }
    });
}
oshoukry commented 7 years ago

Thank you for reporting this issue, java.time.Instant random generator was added and is part of 0.8.5 release. Please update and let me know if you still have any issues.