[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jdt-core-dev] Can IParent.getChildren() return null
|
> I see that IParent.getChildren() is implemented in BinaryType, which
> returns ClassFileInfo.binaryChildren.
> Now ClassFileInfo.binaryChildren seems to be initialized with a null.
>
> Does that mean that everywhere getChildren() is used, there needs to
> be a null check?
IParent.getChildren() is API and guarantees that it does not return null,
so adding null checks at references to that method would be wrong. You
should only write your code against the API, not against a particular
implementation. And if the API is broken, please file a bug.
A better question is: Why is the implementation sound, i.e. does it really
guarantee the API contract?
AFACIS, it's fine: BinaryType#getChildren() calls getClassFileInfo()
before accessing the field. If you follow the implementation, you see that
JavaElement#getElementInfo(IProgressMonitor) either gets the initialized
info from the model manager, or it calls openWhenClosed(..), which calls
generateInfos(..), which calls Openable#generateInfos(..), which calls
ClassFile#buildStructure(..), which calls
ClassFileInfo#readBinaryChildren(..), which initializes
ClassFileInfo#binaryChildren.
HTH,
Markus