TreeSet and compareTo() issue

#1

Hi

I'm trying to use TreeSet but getting NPE on the compareTo() method when it does a find():

at com.objectdb.o.LDR.z(LDR.java:269)
at com.objectdb.o.OBC.aP(OBC.java:1058)
at com.objectdb.o.OBC.aN(OBC.java:976)
at com.objectdb.jpa.EMImpl.find(EMImpl.java:625)
... 123 more
Caused by: java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1192)
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1186)
at com.rpm.model.DropdownValue.compareTo(DropdownValue.java:58)
at com.rpm.model.DropdownValue.compareTo(DropdownValue.java:9)
at java.util.TreeMap.compare(TreeMap.java:1290)
at java.util.TreeMap.put(TreeMap.java:538)
at java.util.TreeSet.add(TreeSet.java:255)
at objectdb.java.util.TreeSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
at java.util.TreeSet.addAll(TreeSet.java:312)
at objectdb.java.util.TreeSet.addAll(Unknown Source)
at java.util.TreeSet.<init>(TreeSet.java:160)
at objectdb.java.util.TreeSet.<init>(Unknown Source)
at objectdb.java.util.TreeSet.__odbNewInstanceWithData(Unknown Source)
at com.objectdb.o.CLT.readStrictly(CLT.java:226)
at com.objectdb.o.MUT.readAndAdjust(MUT.java:500)
at com.objectdb.o.UMR$S.C(UMR.java:1015)
at com.objectdb.o.UMR.B(UMR.java:603)
... 138 more

My compareTo() method looks like this:

@Override
public int compareTo(DropdownValue ddv) {
    return String.CASE_INSENSITIVE_ORDER.compare(dropdownValue, ddv.dropdownValue);
}

The dropdownValue's are accessed through a collection field in another class that uses eager fetch:

@OneToMany(fetch = FetchType.EAGER)
private Set<DropdownValue> dropdownValues = new TreeSet<>();

I presume the NPE is either on the 'dropdownValue' or 'ddv' variable.  Any ideas how to sort this please?

Thanks Russ

#2

Are you sure that there are no null values in the dropdownValue field?

Are your classes enhanced?

If it is an issue with ObjectDB a simple test case the demonstrates it will help.

ObjectDB Support
#3

Sorry for delay...been working on other things.

I've put together a test case app (Maven) that shows the issue.  On the first run through, the process works ok but when you run the app a second time, you get the NPE.  Anyway, hopefully the test app is self-explanatory...I've commented where the NPE occurs.  It's probably something stupid that I'm forgetting to do!

Thanks

Russ

#4

Thank you for the test case. Please note that cascading persist should be added to make the test valid:

    @OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.PERSIST)
    private Set<DropdownValue> dropdownValues = new TreeSet<>();

Please try build 2.6.6_02 that should fix the issue.

ObjectDB Support
#5

Hi

No change I'm afraid after upgrading to 2.6.6_02.  Both the test case and my app are still throwing the same exception:

at com.objectdb.o.QRR.m(QRR.java:549)
at com.objectdb.o.QRR.f(QRR.java:212)
at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:719)
... 6 more
Caused by: java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1192)
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1186)
at treesettest.DropdownValue.compareTo(DropdownValue.java:32)
at treesettest.DropdownValue.compareTo(DropdownValue.java:5)
at java.util.TreeMap.compare(TreeMap.java:1290)
at java.util.TreeMap.put(TreeMap.java:538)
at java.util.TreeSet.add(TreeSet.java:255)
at objectdb.java.util.TreeSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
at java.util.TreeSet.addAll(TreeSet.java:312)
at objectdb.java.util.TreeSet.addAll(Unknown Source)
at com.objectdb.o.TYT.extractCollection(TYT.java:103)
at com.objectdb.o.ENT.extractCollection(ENT.java:1510)
at objectdb.java.util.TreeSet.__odbBeforeAccess(Unknown Source)
at objectdb.java.util.TreeSet.size(Unknown Source)
at com.objectdb.o.CLT.writeStrictly(CLT.java:194)
at com.objectdb.o.TYW.ar(TYW.java:448)
at com.objectdb.o.TYW.au(TYW.java:499)
at com.objectdb.o.TYW.writeElement(TYW.java:321)
at com.objectdb.o.UMR$S.A(UMR.java:1003)
at com.objectdb.o.UMR.z(UMR.java:573)
... 22 more
#6

Sorry about that. Please try build 2.6.6_03.

ObjectDB Support
#7

Thanks, that's fixed it. smiley

Reply