dev@jaxb.java.net

Incorrect JClassAlreadyExistsException

From: Vivek Pandey <Vivek.Pandey_at_Sun.COM>
Date: Tue, 24 Oct 2006 12:13:55 -0700
This problem was reported by a jaxws user. wsimport, while compiling a WSDL uses JCodeModel to generate java code. In this particular case, when there are two classes that wsimport is tring to generate with different capitalization: Adapterexception.java and AdapterException.java,

it results into:

Caused by: com.sun.codemodel.JClassAlreadyExistsException
        at com.sun.codemodel.JPackage._class(JPackage.java:188)
        at com.sun.codemodel.JCodeModel._class(JCodeModel.java:178)
        at com.sun.tools.ws.processor.generator.CustomExceptionGenerator.write(C
ustomExceptionGenerator.java:101)
        at com.sun.tools.ws.processor.generator.CustomExceptionGenerator.registe
rFault(CustomExceptionGenerator.java:91)
        ... 26 more
error: generator error: generator error: com.sun.codemodel.JClassAlreadyExistsEx

The problematic code seems to be in JPackage() where it tries to take care of class names on windows platform by ignoring the case:

JPackage(){
...
 if(JCodeModel.isCaseSensitiveFileSystem)
            upperCaseClassMap = null;
        else
            upperCaseClassMap = new HashMap<String,JDefinedClass>();
...
}

Then in JPackage._class():

// XXX problems caught in the NC constructor
            JDefinedClass c = new JDefinedClass(this, mods, name, classTypeVal);
           
            if( upperCaseClassMap!=null ) {
                JDefinedClass dc = upperCaseClassMap.get(name.toUpperCase());
                if(dc!=null)
                    throw new JClassAlreadyExistsException(dc);
                upperCaseClassMap.put(name.toUpperCase(),c);
            }           
            classes.put(name,c);


How is it supposed to work if a platform like windows has classes with different capitalization?

-vivek.