#25 allowprotect should incl. packageprivate

release_2.1
closed
Lars Kühne
None
5
2012-10-10
2002-01-30
No

If "allowprotected" is set for allowing protected data,
package-private data is not included, even though it
should (by my opinion).

Explanation:

When specifing variables in a class of the form

> public class PubClass
> {
> int testPackagePrivate;
>
> protected int testProtected;
>
> private int testPrivate;
> }

Checkstyle prints out something like this.

> ...
> variable 'testPackagePrivate' must be private and
have accessor methods.
> ...
> variable 'testProtected' must be private and have
accessor methods.
> ...

When "allowprotected" is turned on by

> <checkstyle ...
> allowprotected="true"
> ...>
> ...
> </checkstyle>

checkstyle still complains about the package-private
member by printing out:

> ...
> variable 'testPackagePrivate' must be private and
have accessor methods.
> ...

Variable testProtected is ok now, even though its
access-mode is less restrictiv than package-private.

Is this a bug or a feature.

If this is a feature: Why?

Discussion

  • Lars Kühne
    Lars Kühne
    2002-01-30

    Logged In: YES
    user_id=401384

    This not a bug. In my projects at work package-private
    variables are not allowed, because we found they tend to be
    abused as package wide global variables and because we like
    encapsulation. On the other hand protected variables are OK
    in most of my projects (not my decision).

    If you control the checks implicitly, you have no way to
    find all errors in my projects. In essence, you want to
    control this independently and explicitly, not implicitly.

    RFE #504964 "no default access" requests a new parameter -
    allowPackage - similar to allowProtected. That RFE will
    probably be implemented in the next release. Would that
    solve your problem?

     
  • Logged In: YES
    user_id=354521

    allowPackage would be perfect. Thanks.

     
  • Lars Kühne
    Lars Kühne
    2002-02-05

    Logged In: YES
    user_id=401384

    This is now implemented in CVS and will be available in the
    next release