question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NaN while scanning for annotations with "double" fields

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danwallachcommented, Apr 19, 2019

Verified: fixes the bug.

0reactions
lukehutchcommented, Apr 19, 2019

Thanks for verifying!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preventing NaN from being persisted by Hibernate
My first impression of this would be to look for type that Hibernate persists double as. So you can refactor the set(...) method...
Read more >
classgraph/Lobby - Gitter
As you see, Retention and Target cannot themselves be scanned, but the class is still annotated with the AnnotationInfo for those annotations. The...
Read more >
Java Double isNaN() Method with Examples - Javatpoint
The isNaN() method of Java Double class returns true: If the value of this Object is Not-a-Number (NaN). ... 2.' v ' is...
Read more >
Odyssey CLx Tutorial Guide for Image Studio 3.1 software
1) Double-click in the field under Image Name. 2) Enter a new name. Press Enter when finished. 3) Refer to Chapter 4: Image...
Read more >
Scanning Java Annotations At Runtime - Baeldung
With the help of Java Reflection, we can scan a specific annotated class or annotated method(s) of a specific class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found