Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8073872

Schemagen fails with StackOverflowError if element references containing class

XMLWordPrintable

    • b113
    • Not verified

        Consider the following java class:
        import java.util.*;
        import javax.xml.bind.annotation.*;

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "", propOrder = {
                    "fooObject"
                })
        @XmlRootElement(name = "Foo")

        public class Foo {
           protected List<Foo> fooObject;
           public List<Foo> getFooObject() {
               if (fooObject == null) {
                   fooObject = new ArrayList<Foo>();
               }
               return this.fooObject;
           }
        }

        schemagen invocation for this class fails on latest JDK9/8/7 builds with:
        java.lang.reflect.InvocationTargetException
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:502)
                at com.sun.tools.internal.jxc.SchemaGenerator.run(SchemaGenerator.java:151)
                at com.sun.tools.internal.jxc.SchemaGenerator.run(SchemaGenerator.java:76)
                at com.sun.tools.internal.jxc.SchemaGenerator.main(SchemaGenerator.java:67)
        Caused by: java.lang.RuntimeException: java.lang.StackOverflowError
                at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:144)
                at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:93)
                at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:87)
                at com.sun.tools.internal.jxc.SchemaGenerator$Runner.compile(SchemaGenerator.java:251)
                ... 7 more
        Caused by: java.lang.StackOverflowError
                at java.lang.ref.Reference.<init>(Reference.java:304)
                at java.lang.ref.WeakReference.<init>(WeakReference.java:57)
                at java.lang.reflect.Proxy$Key1.<init>(Proxy.java:439)
                at java.lang.reflect.Proxy$KeyFactory.apply(Proxy.java:545)
                at java.lang.reflect.Proxy$KeyFactory.apply(Proxy.java:539)
                at java.lang.reflect.WeakCache.get(WeakCache.java:120)
                at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
                at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
                at com.sun.xml.internal.txw2.ContainerElement._cast(ContainerElement.java:353)
                at com.sun.xml.internal.txw2.ContainerElement._element(ContainerElement.java:374)
                at com.sun.xml.internal.txw2.ContainerElement.addElement(ContainerElement.java:218)
                at com.sun.xml.internal.txw2.ContainerElement.invoke(ContainerElement.java:145)
                at com.sun.proxy.$Proxy15.element(Unknown Source)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace$2.write(XmlSchemaGenerator.java:1054)
                at com.sun.xml.internal.bind.v2.schemagen.Tree$Optional.write(Tree.java:170)
                at com.sun.xml.internal.bind.v2.schemagen.Tree$Repeated.write(Tree.java:196)
                at com.sun.xml.internal.bind.v2.schemagen.Tree$Group.write(Tree.java:240)
                at com.sun.xml.internal.bind.v2.schemagen.Tree.write(Tree.java:123)
                at com.sun.xml.internal.bind.v2.schemagen.Tree.write(Tree.java:126)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace.writeClass(XmlSchemaGenerator.java:969)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace.writeTypeRef(XmlSchemaGenerator.java:794)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace.writeTypeRef(XmlSchemaGenerator.java:765)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace.access$1800(XmlSchemaGenerator.java:491)
                at com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator$Namespace$2.write(XmlSchemaGenerator.java:1092)

              aefimov Aleksej Efimov
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: