#646 ReturnCount test false positive

release_1.0
closed
Oliver Burn
Tests (17)
7
2013-10-27
2011-07-13
Patrick Lemmens
No

Checkstyle raises a false positive for the "too many returns in method" check when an anonymous class is used within a method that itself has a return value.

The example is below. The method has a single return, but the anonymous class (TabField() {...}) has 2 returns and this seems to be used by Checkstyle in counting the number of returns in the method.

This method shows "too many returns", but there is only 1 in the main method.

Code example:

private TabField createDefaultTabField(final String fieldName, IModel modelTmp) {
    final String tabName = fieldName.substring(TabField.TAB_PREFIX.length());
    TabField defaultTabField = new TabField() {
        /**
         * {@inheritDoc}
         */
        @Override
        public String getTabName() {
            return tabName;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public Class<? extends IModel> getModelType() {
            return IModel.class;
        }
    };
    defaultTabField.init(modelTmp, new ActionMap().init());
    return defaultTabField;
}

Discussion

  • Roman Ivanov
    Roman Ivanov
    2013-10-27

    • status: open --> closed
    • Group: --> release_1.0
     
  • Roman Ivanov
    Roman Ivanov
    2013-10-27

    I failed to reproduce your problem on 5.6 EclipseCS (Checkstyle 5.6).

    please recheck if this is a still problem, if so please report it to https://github.com/checkstyle/checkstyle/issues