False positive : MaximumInheritanceDepth when using Spring ChainableInternalResourceViewResolver

17 views
Skip to first unread message

Charles Morin

unread,
Mar 19, 2018, 9:58:40 AM3/19/18
to SonarQube
Hi,

We are using  Spring 4.3.14.RELEASE and we are slowly transitioning from JSPs to Thymeleaf as our view technology.

Based on our some researches, we have found that the following view resolver would do the trick.

public class ChainableInternalResourceViewResolver extends InternalResourceViewResolver {

    @Override

    protected AbstractUrlBasedView buildView(String viewName) throws Exception {

        String url = getPrefix() + viewName + getSuffix();


        if (getServletContext().getResourceAsStream(url) == null) {

            return new NonExistentView();


        }


        return super.buildView(viewName);


    }


    private static class NonExistentView extends AbstractUrlBasedView {


        @Override

        protected boolean isUrlRequired() {

            return false;

        }

 

        @Override

        protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,

                HttpServletResponse response) throws Exception {

            // Purposely empty, it should never get called

        }


        /**

         * Resource check should always return false

         */

        @Override

        public boolean checkResource(Locale locale) throws Exception {

            return false;

        }

    }

}




However, we get the MaximumInheritanceDepth issue in SonarQube, which I think is a false positive, since we are making use of a framework that we don't have control out of. In this specific case, we simply extend one class from the Spring Framework.


Could the rule be adapted so the number of parents are calculated internally, regardless of the framework used? I think it would be more logical.


Thank you

G. Ann Campbell

unread,
Mar 19, 2018, 10:43:55 AM3/19/18
to SonarQube
Hi,

You may be interested in this earlier thread from this group.


:-)
Ann
Reply all
Reply to author
Forward
0 new messages