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

Null pointer on updating full text index #366

Closed
boxheed opened this issue Oct 29, 2020 · 2 comments
Closed

Null pointer on updating full text index #366

boxheed opened this issue Oct 29, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@boxheed
Copy link

boxheed commented Oct 29, 2020

Hi,

When using a full text index on a field if I update a field that is currently null with a value then the full text indexing of the new value throws a NullPointerException. I've put the stack trace below along with example code that demonstrates the issue. I've found this in 3.4.2 I'm wondering if it's possibly related to the fix for #222

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTokenizer.<init>(StringTokenizer.java:199)
	at java.base/java.util.StringTokenizer.<init>(StringTokenizer.java:221)
	at org.dizitart.no2.fulltext.BaseTextTokenizer.tokenize(BaseTextTokenizer.java:40)
	at org.dizitart.no2.internals.NitriteTextIndexingService.deleteIndex(NitriteTextIndexingService.java:65)
	at org.dizitart.no2.internals.IndexingService.refreshIndexEntry(IndexingService.java:206)
	at org.dizitart.no2.internals.DataService.update(DataService.java:182)
	at org.dizitart.no2.internals.NitriteService.update(NitriteService.java:443)
	at org.dizitart.no2.internals.DefaultNitriteCollection.update(DefaultNitriteCollection.java:322)
	at scrap.NitriteIndexNull.main(NitriteIndexNull.java:42)
package scrap;

import java.io.File;

import org.dizitart.no2.Document;
import org.dizitart.no2.IndexOptions;
import org.dizitart.no2.IndexType;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.NitriteCollection;
import org.dizitart.no2.NitriteId;
import org.dizitart.no2.UpdateOptions;
import org.dizitart.no2.WriteResult;
import org.dizitart.no2.filters.Filters;

public class NitriteIndexNull {

    public static void main(String[] args) {
        File dbFile = new File("/tmp/nitrite.db");
        if(dbFile.exists()) {
            dbFile.delete();
        }
        //create database
        Nitrite nitrite = Nitrite.builder().filePath("/tmp/nitrite.db").openOrCreate();
        //create collection
        NitriteCollection collection = nitrite.getCollection("col");
        //add a record
        Document doc = Document.createDocument("FIELD1", "ABC");
        doc.put("FIELD2", null);
        WriteResult result = collection.update(Filters.eq("FIELD1", "ABC"), doc, UpdateOptions.updateOptions(true, true));
        //get the ID        
        Long id = result.iterator().next().getIdValue();
        //create an indexed field
        collection.createIndex("FIELD2", IndexOptions.indexOptions(IndexType.Fulltext));
        //get document back out
        doc = collection.getById(NitriteId.createId(id));
        //insert a null into the field
        doc.put("FIELD2", null);
        collection.update(Filters.eq("FIELD1", "ABC"), doc, UpdateOptions.updateOptions(true, true));
        //update the null field with an value
        doc.put("FIELD2", "DEF");
        collection.update(Filters.eq("FIELD1", "ABC"), doc, UpdateOptions.updateOptions(true, true));
    }

}
@anidotnet
Copy link
Contributor

I'll have a look

boxheed added a commit to boxheed/nitrite-java that referenced this issue Oct 30, 2020
…ssing into the StringTokenizer as this isn't a null safe call.
anidotnet added a commit that referenced this issue Oct 31, 2020
Issue #366 - added null check to the 'text' variable
@anidotnet anidotnet added the bug label Oct 31, 2020
@anidotnet anidotnet added this to the 3.4.3 milestone Oct 31, 2020
@anidotnet
Copy link
Contributor

fix will be available in 3.4.3-SNAPSHOT

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

No branches or pull requests

2 participants