diff --git a/docs/releasenotes.html b/docs/releasenotes.html index c83609a6e..3ca80df4a 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -148,7 +148,7 @@
  • Ignore comments in GenericIllegalRegexp check, contributed by Daniel Grenner (request 680988, patch 902109). -
  • UnnecessaryParentheses check contributed by +
  • UnnecessaryParentheses check contributed by Eric Roe (patch 911086, request 634834)
  • Added ignoreNonLocal property to UnusedParameter @@ -207,6 +207,9 @@
  • ExplicitInitialization shouldn't report about explicitly initialized member of interface (bug 909619)
  • +
  • DesignForExtension fires for private inner + classes (bug 884035).
  • +
  • Entity resolver for configuration files now handles all previous versions of the configuration DTD locally, without accessing the internet (bug 909987).
  • diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java index 51ef96844..5e752e880 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java @@ -18,10 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks.design; -import com.puppycrawl.tools.checkstyle.api.Check; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.api.DetailAST; -import com.puppycrawl.tools.checkstyle.api.ScopeUtils; +import com.puppycrawl.tools.checkstyle.api.*; /** * Checks that classes are designed for inheritance. @@ -53,7 +50,7 @@ import com.puppycrawl.tools.checkstyle.api.ScopeUtils; *

    * * @author lkuehne - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class DesignForExtensionCheck extends Check { @@ -81,6 +78,13 @@ public class DesignForExtensionCheck extends Check return; } + // method is ok if containing class is not visible in API and + // cannot be extended by 3rd parties (bug #884035) + if (!ScopeUtils.getSurroundingScope(aAST).isIn(Scope.PROTECTED)) + { + return; + } + // method is ok if it is implementation can verified to be empty // Note: native methods don't have impl in java code, so // implementation can be null even if method not abstract diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/InputDesignForExtension.java b/src/testinputs/com/puppycrawl/tools/checkstyle/InputDesignForExtension.java index e27032551..ca75f81aa 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/InputDesignForExtension.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/InputDesignForExtension.java @@ -49,7 +49,24 @@ public class InputDesignForExtension } // has a potentially complex implementation in native code. - // We can't check that, so to be safe DesignForExtension requirves + // We can't check that, so to be safe DesignForExtension requires // native methods to also be final public native void aNativeMethod(); + + // tries to trigger bug #884035 + // MyComparator is a private class, so there cannot be subclasses + // and it should not be neccessary to declare compare() as final + private class MyComparator implements java.util.Comparator + { + public int compare(Object o1, Object o2) + { + // some complex stuff that would normally trigger an error report + if (o1.hashCode() > o2.hashCode()) { + return -1; + } + else { + return 1; + } + } + } }