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
Cursor crashes with java.lang.NullPointerException: null #63
Comments
Could you please provide the code to reproduce this error? |
I could not reproduce this issue. Please provide your response to reproduce this otherwise I have to close this issue. |
seems to happen when multiple threads try to access the cursor. |
Based on your input I have constructed the below test cases, but again I am unable to reproduce this. Could you please try to modify the below test case to match your scenario and reproduce this error? @Indices({
@Index(value = "name", type = IndexType.Fulltext)
})
public class PersonEntity {
@Id
private String uuid;
private String name;
private String status;
private PersonEntity friend;
private Date dateCreated;
public PersonEntity() {
this.uuid = UUID.randomUUID().toString();
this.dateCreated = new Date();
}
public PersonEntity(String name) {
this.uuid = UUID.randomUUID().toString();
this.name = name;
this.dateCreated = new Date();
}
// getter and setter...
}
@Test
public void testIssue63() throws InterruptedException {
PersonEntity p1 = new PersonEntity("abcd");
p1.setStatus("Married");
PersonEntity p2 = new PersonEntity("efgh");
p2.setStatus("Married");
PersonEntity p3 = new PersonEntity("ijkl");
p3.setStatus("Un-Married");
ObjectRepository<PersonEntity> repository = db.getRepository(PersonEntity.class);
repository.insert(p1);
repository.insert(p2);
repository.insert(p3);
final CountDownLatch latch = new CountDownLatch(100);
ExecutorService executor = Executors.newFixedThreadPool(10);
final Cursor<PersonEntity> cursor = repository.find();
// now trying to access same cursor from 100 threads
for (int i = 0; i < 100; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
for (PersonEntity entity : cursor) {
assertTrue(entity.getStatus().equals("Married")
|| entity.getStatus().equals("Un-Married"));
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
latch.countDown();
}
}
});
}
latch.await();
}
|
I got a similar error on accessing the same cursor from 5 threads:
One cursor per threads doesn't work too (error: db already open), What is the trick? |
@swissfreedev I have modified your code a bit as follows: @Test
public void testIssue63_2() throws InterruptedException, IOException {
Nitrite db = Nitrite.builder().compressed().filePath("/tmp/nitrite.db").openOrCreate(); //ohne gummi
ObjectRepository<PersonEntity> repRegion = db.getRepository(PersonEntity.class);
PersonEntity p1 = new PersonEntity("abcd");
p1.setStatus("Married");
PersonEntity p2 = new PersonEntity("efgh");
p2.setStatus("Married");
PersonEntity p3 = new PersonEntity("ijkl");
p3.setStatus("Un-Married");
repRegion.insert(p1);
repRegion.insert(p2);
repRegion.insert(p3);
final Cursor<PersonEntity> cursor = repRegion.find();
CountDownLatch latch = new CountDownLatch(5);
TestThreadMultiCursor t1 = new TestThreadMultiCursor(cursor, 1, latch);
TestThreadMultiCursor t2 = new TestThreadMultiCursor(cursor, 2, latch);
TestThreadMultiCursor t3 = new TestThreadMultiCursor(cursor, 3, latch);
TestThreadMultiCursor t4 = new TestThreadMultiCursor(cursor, 4, latch);
TestThreadMultiCursor t5 = new TestThreadMultiCursor(cursor, 5, latch);
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
latch.await();
Files.delete(Paths.get("/tmp/nitrite.db"));
}
public class TestThreadMultiCursor extends Thread {
Integer threadID;
Cursor<PersonEntity> cursorRegion;
CountDownLatch latch;
public TestThreadMultiCursor(Cursor<PersonEntity> cursorRegion, Integer threadID, CountDownLatch latch) {
this.threadID = threadID;
this.cursorRegion = cursorRegion;
this.latch = latch;
}
public void run() {
System.out.println("Thread " + threadID);
for (PersonEntity t : cursorRegion) {
System.out.println(threadID + ". " + t.getName());
}
latch.countDown();
}
} But still I could not reproduce it. Can you please provide some additional details like - OS, system arch, java version etc? |
Hi Anindya, in my office: win10, netbeans8.2, jdk8, nitrite 2.1.0 I can upload the entire project if it helps? funny, don't tell me it's again a win10 issue ;-) |
In my experience lots of funny things happen in Windows. This is the reason why I moved away from it long ago for my development and day to day work :). It would help immensely if you can test your code on suse. Meantime I'll test it on my Win10 also. Let's see what happens! |
Oh @swissfreedev one more thing I just noticed. I see @wojsys and you are running old version of nitrite. Is it possible for you to test it against 2.2.0-SNAPSHOT in Win10? |
Ok this time win10 is innocent, I got the exception on suse leap 43.2 as well, next step is the update to 2.2.0, news will follow... test startet db=datamulti.db |
Really strange. Can you please upload your sample project here? |
here it comes: TestMulti() for creating test entries, TestMultiCursor() for producing the error |
more and more strange, in this case I can omit a random test with snapshot 2.2.0 |
Superb!!!! I am eager to see the final product. Great job indeed. |
for my own usage I basically added: connect /disconnect since nitrite allows just one connection and its weird to get always the "already connected" error while running two programs, remember/load database path in the local preferencies, direct and quick start without intermediate dialogs, and some cosmetical features I would now like to add an edit mode if this isn't a big deal, and a table sql-like view in studio3t... |
Another development on this issue. I tried it in my office machine - Ubuntu 14.04 (64-bit) with JDK 1.8.0_102. I can see the NPE while using nitrite 2.1.0, but never encountered this with nitrite 2.1.1 or 2.2.0-SNAPSHOT (tried like 30 times with your uploaded code). Could you please try your code with 2.2.0-SNAPSHOT as well in your machine and share the result? |
yes, I'm curious to see what happens, i'll tell you the results soon |
Good news: you are right, I switched to 2.1.1 and 2.2.0 the issue is no more reproducible... so just do not use older versions |
Great, so I can close this issue. @wojsys please revert back if you are seeing this issue in 2.2.0-SNAPSHOT. On a separate note @swissfreedev I could not thank you enough for being a backer for this project in https://opencollective.com/nitrite-database. It will surely inspire me a lot more to invest my time in this project. Cheers. |
java.lang.NullPointerException: null
at org.h2.mvstore.Page.getRawChildPageCount(Page.java:868) ~[h2-mvstore-1.4.196.jar:1.4.196]
at org.h2.mvstore.MVMap.getChildPageCount(MVMap.java:1179) ~[h2-mvstore-1.4.196.jar:1.4.196]
at org.h2.mvstore.Cursor.fetchNext(Cursor.java:149) ~[h2-mvstore-1.4.196.jar:1.4.196]
at org.h2.mvstore.Cursor.next(Cursor.java:50) ~[h2-mvstore-1.4.196.jar:1.4.196]
at org.dizitart.no2.internals.DocumentCursor$DocumentCursorIterator.next(DocumentCursor.java:106) ~[nitrite-2.1.1.jar:na]
at org.dizitart.no2.internals.DocumentCursor$DocumentCursorIterator.next(DocumentCursor.java:92) ~[nitrite-2.1.1.jar:na]
at org.dizitart.no2.objects.ObjectCursor$ObjectCursorIterator.next(ObjectCursor.java:108) ~[nitrite-2.1.1.jar:na]
The text was updated successfully, but these errors were encountered: