NaN while scanning for annotations with "double" fields
See original GitHub issueI’m working on a Java-based autograder for the class that I’ll be teaching this fall. The broad idea is that you put annotations on unit tests to say how many points they’re worth.
Our annotations look something like this:
@GradeTopic(project = "Sorting", topic = "HeapSort")
public class HeapSortTest {
@Test
@Grade(project = "Sorting", topic = "HeapSort", points = 0.4)
public void heapSortStrings() {
TestAnySorter.exerciseStrings(new HeapSort<>());
}
@Test
@Grade(project = "Sorting", topic = "HeapSort", points = 0.4)
public void heapSortIntegers() {
TestAnySorter.exerciseIntegers(new HeapSort<>());
}
}
The corresponding definition of @Grade
is pretty straightforward:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
@Repeatable(Grades.class)
public @interface Grade {
String project();
String topic();
double points();
double maxPoints() default 0.0;
}
What happens:
When I’ve got double
values like the number of points, I’ve found that sometimes I get NaN
rather than the number. You can see this in action if you fetch this commit and run ./gradlew :brokenExampleSort:autograderDebugAnnotations
:
https://github.com/RiceComp215-Staff/RiceChecks/tree/c6d5d26024b2a0dc3b89e998e70ca899c26fd6a6
The output will have ClassGraph logging mixed in with my own logging, but you’ll see something like this:
2019-04-18T14:30:02.753-0500 ClassGraph ------------------ Method: @org.junit.jupiter.api.Test @edu.rice.autograder.annotations.Grade(project="Sorting", topic="HeapSort", points=NaN) public void heapSortStrings()
In this case, something about 0.4
points in HeapSortTest.java
is causing it to become NaN
. If you look instead at the adjacent InsertionSortTest.java
, where it’s using 0.5
points, then everything seems completely fine. If you edit those 0.4
numbers and change them to 0.5
, then everything again works.
I’ve found that integers never cause a problem. The problems only manifest with fractions between 0 and 1, and exactly which fractions are accepted and which are rejected is hard to predict. Pick a number and flip a coin for whether it’s accepted or rejected.
FWIW, I’m running with OpenJDK 11 (Amazon Corretto) on macOS 10.14.4 with Kotlin 1.3.30 and the latest ClassGraph 4.8.24.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Verified: fixes the bug.
Thanks for verifying!