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

IntervalTree#remove null pointer exception #1405

Closed
Sirius902 opened this issue Jan 11, 2024 · 4 comments
Closed

IntervalTree#remove null pointer exception #1405

Sirius902 opened this issue Jan 11, 2024 · 4 comments

Comments

@Sirius902
Copy link

The following program causes a null pointer exception to be thrown. I would expect it to complete successfully and output false.

import edu.stanford.nlp.util.Interval;
import edu.stanford.nlp.util.IntervalTree;

public class Main {
    public static void main(String[] args) {
        var tree = new IntervalTree<Integer, Interval<Integer>>();
        tree.add(Interval.toInterval(0, 1));
        tree.add(Interval.toInterval(2, 5));

        tree.remove(Interval.toInterval(2, 5));

        System.out.println(tree.overlaps(Interval.toInterval(2, 3)));
    }
}
Exception in thread "main" java.lang.NullPointerException: Cannot read field "value" because "anotherInteger" is null
	at java.base/java.lang.Integer.compareTo(Integer.java:1466)
	at java.base/java.lang.Integer.compareTo(Integer.java:72)
	at edu.stanford.nlp.util.Interval.max(Interval.java:424)
	at edu.stanford.nlp.util.IntervalTree.remove(IntervalTree.java:284)
	at edu.stanford.nlp.util.IntervalTree.remove(IntervalTree.java:214)
	at test.Main.main(Main.java:13)
@Sirius902 Sirius902 changed the title IntervalTree<>::remove null pointer exception IntervalTree#remove null pointer exception Jan 11, 2024
@AngledLuffa
Copy link
Contributor

Gah, this class is terrible. Zero documentation and apparently even the most basic functionality isn't tested. Thanks so much for uncovering it

@AngledLuffa
Copy link
Contributor

Testing on other trees of size two, it also crashes if you insert things in such an order that the left child of the balanced tree is being deleted or if the root of the balanced tree is deleted. You would think such a thing would be found before the other 500 lines of code got written.

What's debugging got to do with it, anyway?
What's debugging but a sweet old fashioned notion?
Who needs a unit test when a test can be broken?

AngledLuffa added a commit that referenced this issue Jan 11, 2024
…htmost, or rootmost nodes. I'm the guy who tests his code. You must be the other guy. Addresses #1405
AngledLuffa added a commit that referenced this issue Jan 12, 2024
…htmost, or rootmost nodes. I'm the guy who tests his code. You must be the other guy. Addresses #1405
@Sirius902
Copy link
Author

@AngledLuffa Thanks for the quick reply! I found the issue using a larger set of test data but cf11603 seems to have addressed the issue there as well.

@AngledLuffa
Copy link
Contributor

Now released in 4,.5.6

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