-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should ProtectedMethodInFinalClass really exist? #901
Comments
@victornoel/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot! |
@victornoel why would you use |
@krzyk see the following example: public abstract class AbstractClass {
protected abstract void method();
}
// here qulice complains with ProtectedMethodInFinalClassCheck
public final class FinalClass extends AbstractClass {
@Override
protected void method() {
// implem
}
}
// here javac complains with "Cannot reduce the visibility of the inherited method from AbstractClass"
public final class FinalClass extends AbstractClass {
@Override
void method() {
// implem
}
}
// here we made a method not meant to be exposed public
public final class FinalClass extends AbstractClass {
@Override
public void method() {
// implem
}
} To answer you question: default does not work in that case, so I have to make it public, which I think is worst design than having a protected method in a final class (or it should only be for non-overridden methods). |
@victornoel Oh, in that case it should be excluded in case of |
@0crat in |
@0crat assign me |
Bug was reported, see §29: +15 point(s) just awarded to @victornoel/z |
@victornoel fixed in #915, it will be available with next qulice release. Please close this issue. |
@krzyk don't you think the rule should be stricter and only allow it in case there is an override AND the superclass method is protected? |
@victornoel but this will be quite a narrow case when someone widens the scope from default to protected, and it has to be in a class that has visibility of that default method (so in the same package). Please create a new bug for this (we will probably need to convert this to PMD check in that case). |
@krzyk yep, I understand, this issue is fixed anyway :) |
Job was finished in 3 hours, bonus for fast delivery is possible (see §36) |
The job #901 is now out of scope |
When implementing a final class that extends an abstract class with protected methods, it feels very wrong to me to mark the implementations of those methods as being public.
But with the rule
ProtectedMethodInFinalClassCheck
, I am forced to make them public.This exposes undesired internal behaviour to the outside and thus seem a bad idea.
The text was updated successfully, but these errors were encountered: