Skip to content
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

DateTimeException #96

Closed
sixcorners opened this issue Jan 6, 2017 · 1 comment
Closed

DateTimeException #96

sixcorners opened this issue Jan 6, 2017 · 1 comment

Comments

@sixcorners
Copy link

sixcorners commented Jan 6, 2017

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants