javaee / metro-jax-ws

https://javaee.github.io/metro-jax-ws/
Other
132 stars 68 forks source link

JAXB xjc CClassInfo constructor with fullname constructs wrong package #1187

Open glassfishrobot opened 8 years ago

glassfishrobot commented 8 years ago

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".

**com.sun.tools.xjc.model.CClassInfo**
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('.');
        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('.');

glassfishrobot commented 8 years ago

Reported by dschulten

glassfishrobot commented 8 years ago

dschulten said: I have added this issue here although the jaxb project might seem more appropriate, because the jaxb jira gives me an error "Assignee: The default assignee does NOT have ASSIGNABLE permission OR Unassigned issues are turned off."

When that problem is resolved, I can gladly re-create this issue in the jaxb jira.

glassfishrobot commented 7 years ago

dschulten said: I was able to create https://java.net/jira/browse/JAXB-1114. This can be closed.

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAX_WS-1187