Closed davekipfer closed 9 years ago
Thanks for finding it. Fixed in the trunk. Is it urgent for you to get a new release, or can I await some more issues?
No urgent need, I think I have a workaround for now.
Something like wModel._package ("com")
?
No, what I do is instead of checking wCurrentPackage.parent() in the loop, I check to see if wCurrentPackage is a package just under the root package by checking for any '.' in the name.
Alrighty. Is fixed in release 2.7.11. Stay tuned.
Much appreciated!
When producing a code model using JCodeModel.ref(), the following operation doesn't work as expected:
// Create JCodeModel
JCodeModel wModel = new JCodeModel();
// Reflect into class
AbstractJClass wClass = wModel.ref(com.redfish.prod.Boomer.class);
// Walk up to the root package
JPackage wCurrentPackage = null;
for (wCurrentPackage = wClass._package(); wCurrentPackage.parent() != null; wCurrentPackage = wCurrentPackage.parent());
JPackage wRoot = wCurrentPackage;
The problem occurs in JPackage.parent() on the package just above the root package. The name is just "com", and so the existing code:
/**
Gets the parent package, or null if this class is the root package. */
@Nullable
public JPackage parent ()
{
if (m_sName.length () == 0)
final int idx = m_sName.lastIndexOf ('.');
return m_aOwner._package (m_sName.substring (0, idx));
}
The result in the lowest level non-root package is a StringIndexOutOfBoundsException as "idx" is set to -1.
This seems to be correct usage based on what I seei in the method's documentation, but clearly it can't handle it.