-
Notifications
You must be signed in to change notification settings - Fork 17
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
java.lang.NullPointerException when trying to access AllenUtils.getOntologies().getAncestors() #47
Comments
Hi @judith-baka , thanks for catching this. It is indeed a bug. What is happening is that Internally, this initialization is meant to be done on an "as-needed" basis (i.e., on the first call of an from scyjava import jimport
AllenUtils = jimport('sc.fiji.snt.annotation.AllenUtils')
areas = AllenUtils.getOntologies()
for a in areas:
tree_path = list(ij.py.from_java(a.getTreePath()))
ancestors = tree_path[:-1]
if not ancestors:
print(tree_path[0].name()) # Whole Brain On my machine, The reason for not initializing So, one easy fix that immediately comes to mind is to replace all direct manipulation of the |
calling getTreePath() should work.
I noticed that too. Maybe we are being too lax? Do collections exist in Python? Maybe the cast is not needed if we return a List rather than a Collection?: public static List<AllenCompartment> getOntologies() {
return new AllenTreeModel().getOntologies(); // Change this to also return a List
} Either way, it is probably the right thing to do? I had though of always using the most general representation, bu Collection may be an exaggeration? Specially if we want to API to be script-friendly? |
agreed |
If adopting list works, we probably should extend it to other classes too |
I'll start investigating 🕵️♂️ |
- Ensure the parentStructure attribute is initialized by calling getTreePath() - Fix bug in getChildren() - Set pre-computed volume for mouse brain root OBJMesh - Create test for AllenCompartment functionality - misc code cleanup
- ensure parentStructure attribute is initialized by calling AllenCompartment.getTreePath() - fix bug in AllenCompartment.getChildren() - set pre-computed volume for mouse brain root OBJMesh - AllenUtils.getOntologies() returns List instead of Collection - create tests for AllenCompartment and AllenUtils - misc code cleanup
@tferr the PR I just linked has fixes for most of what we talked about here. RE: the migration of public methods returning Would it make sense to open a different issue for those? |
Yes. Definitely. Does it solve the pyimagej issue? |
from scyjava import jimport
AllenUtils = jimport('sc.fiji.snt.annotation.AllenUtils')
areas = AllenUtils.getOntologies()
print(type(areas)) # <java class 'java.util.ArrayList'>
print(type(ij.py.from_java(areas))) # <class 'scyjava.JavaList'> Apparently not... |
bummer. Maybe we should open an issue in pyimagej? Now that we are returning lists, seems rather silly that it is not casted immediately? |
Oh, wait, didn't see the link (was reading on the phone). Shall we return ArrayList instead? |
I'll try that, sure |
I get the same result when returning |
bummer. let's open the issue. Meanwhile I'll try to release a new version over the weekend. I am looking at the double entry in linux. |
sounds good 👍 |
@tferr in case you didn't see this imagej/pyimagej#100 |
nice. way more concise. Do you have time to update the notebooks? |
on it |
Describe the bug
You get java.lang.NullPointerException when trying to access AllenUtils.getOntologies().getAncestors()
To Reproduce
gives "java.lang.NullPointerException"
But there is a hint:
if you do:
no error..
The text was updated successfully, but these errors were encountered: