method is null

Project:JNode Core
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

in some contexts some methods are null and cant be invoced. Invocation fails with NPE.

for example, PriorityQueue::add present, but PriorityQueue::offer does not. PriorityQueue::add delegates PriorityQueue::offer (just calls it).

If i call PriorityQueue::add, NPE happens in PriorityQueue::add at calling offer. If i call PriorityQueue::offer, NPE happens in my code.

Is it a bug or for some contexts "magic list" of compiled classes/methods required?

#1

Could you be more speciffic about the context where you see this problem?

#2

I used it in VmScheduler::addToSleepQueue like this:

sleepQueueLock.lock();
try {
    sleepQueue.add(thread);
} finally {
    sleepQueueLock.unlock();
}

exception will be in PriorityQueue::add when it calls PriorityQueue::offer.

If i write

sleepQueueLock.lock();
try {
    sleepQueue.offer(thread);
} finally {
    sleepQueueLock.unlock();
}

Exception happens in my code at line when i call offer.

#3

I think you should try with PriorityQueue something similiar to what is done to ArrayList and HashMap.
VmScheduler is instantiated build time and used runtime and so are the objects directly refrenced by it. This creates delicate problems.
My sugestion: please investigate org.jnode.util.BootabeArrayList and org.jnode.util.BootableHashMap and based on them try to create a BootablePriorityQueue and try to use this instead of the original PriorityQueue.
There are only a few places where this trick is needed but for instance if you replace in the JNode sources a useplace of BootableArrayList with ArrayList you will hit a similar problem. Pay special attention to the method verifyBeforeEmit().

#4

Also strange: if i use PriorityQueue in constructor of VmScheduler, it works and no any NPE's..

#5

Yes, BootablePriorityQueue works well.
I guess objects in this context created during building and serialized. And during boot they de-serialized. But, why so strange NPE?

#6

And, whats a problem with java.util.* ? why do not need to make BootableString, BootableVmThreadQueue, etc.?

#7

I wonder if this a consequence of the "flakiness" I described in the following issue.

http://jnode.org/node/932

Bear in mind that I didn't (and still don't) really understand the boot image loader, so my theories about it could be totally wrong. (And the original issue is "moot" of course, as explained by other comments.)