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

JavacTrees should use Types.skipTypeVars() to get the upper bound of type variables

    Details

    • Subcomponent:
    • Introduced In Build:
      b75
    • Introduced In Version:
      8
    • Resolved In Build:
      b158
    • CPU:
      x86_64
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_121"
        Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
        Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Running Windows 7 64bit, Installed Java JDK and JRE (32bit and 64bit),
        using 64bit Java for compiler task, using opensource build tool Gradle version 2.14.1 to build and run applications

        A DESCRIPTION OF THE PROBLEM :
        The exception is raised while creating the javadoc for our project. We (my company and I) are developing database applications based on Java. We are using Frameworks like Spring, Spring Boot, JDOM2, Apache Camel and Jetty.

        Running the javadoc executable as standalone with any Gradle taks it does NOT work either.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Call this with the class source code send with this report:

        "C:\Program Files\Java\jdk1.8.0_91\bin\javadoc.exe" U:\WIB\git\xscore\core\src\main\java\com\din\xscore\core\domain\filter\builder\TreeFilterBuilder.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The excepted result is a complete java API documentation of our application classes.
        ACTUAL -
        No result. The process crashes.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$TypeVariableSymbol cannot be cast to com.sun.tools.javac.code.Symbol$ClassSymbol
                at com.sun.tools.javac.api.JavacTrees.attributeDocReference(JavacTrees.java:410)
                at com.sun.tools.javac.api.JavacTrees.getElement(JavacTrees.java:345)
                at com.sun.tools.doclint.Checker.visitReference(Checker.java:756)
                at com.sun.tools.doclint.Checker.visitReference(Checker.java:95)
                at com.sun.tools.javac.tree.DCTree$DCReference.accept(DCTree.java:523)
                at com.sun.source.util.DocTreePathScanner.scan(DocTreePathScanner.java:65)
                at com.sun.source.util.DocTreeScanner.visitLink(DocTreeScanner.java:177)
                at com.sun.tools.doclint.Checker.visitLink(Checker.java:684)
                at com.sun.tools.doclint.Checker.visitLink(Checker.java:95)
                at com.sun.tools.javac.tree.DCTree$DCLink.accept(DCTree.java:422)
                at com.sun.source.util.DocTreePathScanner.scan(DocTreePathScanner.java:65)
                at com.sun.source.util.DocTreeScanner.scanAndReduce(DocTreeScanner.java:81)
                at com.sun.source.util.DocTreeScanner.scan(DocTreeScanner.java:92)
                at com.sun.source.util.DocTreeScanner.scanAndReduce(DocTreeScanner.java:100)
                at com.sun.source.util.DocTreeScanner.visitDocComment(DocTreeScanner.java:140)
                at com.sun.tools.doclint.Checker.visitDocComment(Checker.java:217)
                at com.sun.tools.doclint.Checker.visitDocComment(Checker.java:95)
                at com.sun.tools.javac.tree.DCTree$DCDocComment.accept(DCTree.java:122)
                at com.sun.source.util.DocTreePathScanner.scan(DocTreePathScanner.java:47)
                at com.sun.tools.doclint.Checker.scan(Checker.java:179)
                at com.sun.tools.doclint.DocLint.scan(DocLint.java:319)
                at com.sun.tools.javadoc.DocImpl.comment(DocImpl.java:133)
                at com.sun.tools.javadoc.DocImpl.tags(DocImpl.java:154)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.checkOnPropertiesTags(VisibleMemberMap.java:686)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.getClassMembers(VisibleMemberMap.java:464)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.addMembers(VisibleMemberMap.java:372)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.mapClass(VisibleMemberMap.java:346)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.mapClass(VisibleMemberMap.java:358)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.build(VisibleMemberMap.java:341)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap$ClassMembers.access$100(VisibleMemberMap.java:291)
                at com.sun.tools.doclets.internal.toolkit.util.VisibleMemberMap.<init>(VisibleMemberMap.java:127)
                at com.sun.tools.doclets.internal.toolkit.builders.MemberSummaryBuilder.<init>(MemberSummaryBuilder.java:82)
                at com.sun.tools.doclets.internal.toolkit.builders.MemberSummaryBuilder.getInstance(MemberSummaryBuilder.java:101)
                at com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory.getMemberSummaryBuilder(BuilderFactory.java:278)
                at com.sun.tools.doclets.formats.html.ClassWriterImpl.getNavSummaryLinks(ClassWriterImpl.java:641)
                at com.sun.tools.doclets.formats.html.ClassWriterImpl.addSummaryDetailLinks(ClassWriterImpl.java:622)
                at com.sun.tools.doclets.formats.html.HtmlDocletWriter.addNavLinks(HtmlDocletWriter.java:560)
                at com.sun.tools.doclets.formats.html.ClassWriterImpl.getHeader(ClassWriterImpl.java:165)
                at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.buildClassDoc(ClassBuilder.java:145)
                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:498)
                at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.invokeMethod(AbstractBuilder.java:180)
                at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:135)
                at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.build(ClassBuilder.java:120)
                at com.sun.tools.doclets.formats.html.HtmlDoclet.generateClassFiles(HtmlDoclet.java:189)
                at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.generateClassFiles(AbstractDoclet.java:205)
                at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.generateClassFiles(AbstractDoclet.java:189)
                at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:137)
                at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:82)
                at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:80)
                at com.sun.tools.doclets.standard.Standard.start(Standard.java:39)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        1 error
                at java.lang.reflect.Method.invoke(Method.java:498)
                at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:310)
                at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:189)
                at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:366)
                at com.sun.tools.javadoc.Start.begin(Start.java:219)
                at com.sun.tools.javadoc.Start.begin(Start.java:205)
                at com.sun.tools.javadoc.Main.execute(Main.java:64)
                at com.sun.tools.javadoc.Main.main(Main.java:54)
        javadoc: error - java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$TypeVariableSymbol cannot be cast to com.sun.tools.javac.code.Symbol$ClassSymbol

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package com.din.xscore.core.domain.filter.builder;

        import com.din.xscore.core.domain.filter.TreeFilter;
        import com.din.xscore.core.repository.FilterRepository;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        import java.util.Collection;
        import java.util.HashMap;
        import java.util.Map;

        /**
         * This abstract class defines filter builder working only with {@link TreeFilter}.
         *
         * <p>Any implementation of this class are <b>not</b> thread-safe! However the build process
         * could be synchronized externally to support multiple threads or the filter builder instance could be reuse
         * by a single thread by calling the build method again (resets all cached data).</p>
         *
         * @author WIB
         * @version 1.0
         * @since 2016-08-08
         */
        public abstract class TreeFilterBuilder<F extends TreeFilter, T> implements FilterBuilder<F, T>
        {
        protected final Logger log = LoggerFactory.getLogger(this.getClass());

        /**
        * The filter repository.
        */
        protected final FilterRepository<F> repository;

        /**
        * A cache, used while build process.
        */
        private final Map<String, F> cache;

        /**
        * All constructed tree root filter.
        */
        private final Map<String, F> roots;

        /**
        * All incoming filter expressions ("leafs" of the in-memory tree).
        */
        private final Map<String, F> leafs;

        /**
        * Constructor.
        *
        * <p>This constructor will create internal caches with the following initial sizes:
        * <ul>
        * <li>Roots: 5</li>
        * <li>Cache: 20</li>
        * <li>Leafs: 10</li>
        * </ul>
        * </p>
        *
        * @param repository filter repository instance supporting {@link TreeFilter}
        */
        protected TreeFilterBuilder(FilterRepository<F> repository)
        {
        this.repository = repository;

        this.roots = new HashMap<>(5);
        this.cache = new HashMap<>(20);
        this.leafs = new HashMap<>(10);
        }

        @Override
        @SuppressWarnings ("unchecked")
        public Collection<F> build(Map<String, T> source)
        {
        // clear caches
        leafs.clear();
        roots.clear();
        cache.clear();

        // read configuration one by one
        for(String key : source.keySet())
        {
        // get filter if known
        F leaf = this.repository.get(key);

        if(leaf!=null)
        {
        // clone filter (to reuse filter instance)
        leaf = (F) leaf.clone();

        configureFilter(leaf, source.get(key));

        log.debug("{}: {}", leaf.getName(), leaf.getDefinition());

        this.leafs.put(leaf.getName(), leaf);
        }
        }

        // build up in-memory tree
        walkTree(this.leafs);

        // return all constructed root filter
        return this.roots.values();
        }

        /**
        * Walks up the in-memory filter tree processing (clone and build) all filters per tree level recursively.
        *
        * @param filters tree level as filter map
        */
        private void walkTree(Map<String, F> filters)
        {
        Map<String, F> treeLevel = new HashMap<>();

        // walk over every filter on this level
        for(String key : filters.keySet())
        {
        // get the filter
        F filter = filters.get(key);

        // if root move to roots
        if(filter.isRoot())
        this.roots.putIfAbsent(filter.getName(), filter);
        else {
        // otherwise process and get parent
        F parent = prepareParent(filter);

        //log.debug("walkTree: "+parent.definition());

        // add to next tree level
        treeLevel.put(parent.getName(), parent);
        }
        }

        // proceed to next level (if no more leafs left stop)
        if(treeLevel.size()>0)
        walkTree(treeLevel);
        }

        /**
        * Configures the given filter instance with the given configuration.
        *
        * <p>This method should call {@link F#build()}.</p>
        *
        * @param filter filter instance
        * @param config configuration instance
        *
        * @see #build(Map)
        */
        protected abstract void configureFilter(F filter, T config);

        /**
        * Prepares the parent tree filter of the given filter for processing.
        *
        * <p>"Preparation" means any operation(s) to retrieve the parent from
        * the child filter (could include cloning, building, setting parameters).</p>
        *
        * @param filter filter instance
        *
        * @return prepared parent filter
        */
        protected abstract F prepareParent(F filter);

        /**
        * Returns a flag indicating if the filter with the given name is cached already.
        *
        * @param name unique name of a filter, filter key
        *
        * @return <code>true</code>, if the filter with the given name is cached, <code>false</code> otherwise
        */
        protected boolean isCached(String name)
        {
        return this.cache.containsKey(name);
        }

        /**
        * Caches a filter instance.
        *
        * @param filter filter to cache
        */
        protected void cache(F filter)
        {
        this.cache.put(filter.getName(), filter);
        }

        /**
        * Retrieves a cached filter instance.
        *
        * @param name unique name of a filter, filter key
        *
        * @return cached filter instance, or <code>null</code> if there is no cached filter with that name
        */
        protected F cache(String name)
        {
        return this.cache.get(name);
        }
        }

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  vromero Vicente Arturo Romero Zaldivar
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: