You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CClassInfo has the below constructor which takes a JCodeModel and a fullName. The fullName parameter should be the FQCN of the class. However, if the fullName starts with a package having more than one name segment (like "com.example" which has two segments), the following code fails, because it puts the resulting CClassInfo into the package that is the first segment.
Assuming a fullName "com.example.MyClass", the code below will find that the indexOf '.' is 3, and from there everything goes wrong.
The constructor sets this.parent to the package "com" and it will use fullName.substring(idx+1) to determine the shortName, i.e. he shortName ends up being "example.MyClass".
CClassInfo has the below constructor which takes a JCodeModel and a fullName. The fullName parameter should be the FQCN of the class. However, if the fullName starts with a package having more than one name segment (like "com.example" which has two segments), the following code fails, because it puts the resulting CClassInfo into the package that is the first segment.
Assuming a fullName "com.example.MyClass", the code below will find that the indexOf '.' is 3, and from there everything goes wrong.
The constructor sets this.parent to the package "com" and it will use fullName.substring(idx+1) to determine the shortName, i.e. he shortName ends up being "example.MyClass".
{code title=com.sun.tools.xjc.model.CClassInfo|borderStyle=solid}
public CClassInfo(Model model,JCodeModel cm, String fullName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) {
super(model,source,location,customizations);
this.model = model;
int idx = fullName.indexOf('.'); <-- must be lastIndexOf('.')
if(idx<0)
{ this.parent = model.getPackage(cm.rootPackage()); this.shortName = model.allocator.assignClassName(parent,fullName); }
else
{ this.parent = model.getPackage(cm._package(fullName.substring(0,idx))); this.shortName = model.allocator.assignClassName(parent,fullName.substring(idx+1)); }
this.typeName = typeName;
this.elementName = elementName;
model.add(this);
}
The line
int idx = fullName.indexOf('.');
should be
int idx = fullName.lastIndexOf('.');
Affected Versions
[2.2.11]
The text was updated successfully, but these errors were encountered: