-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add Check Support for Java 17 Sealed Classes: IllegalType #15010
Comments
I keep coming back to this one, and feel like it is kind of weird, so I am having a hard time decided what to do here. In practice, I would use IllegalType for the following:
However, with |
To help clarify things, this only seems to violate declared types, it won't violate instance usages of the type. Example from https://checkstyle.org/checks/coding/illegaltype.html#Example1-config :
It will ban the class from being extended, as that is being declared as a sub-type. I think this may need to be added to the documentation to help make this check clearer.
I mainly use I had a project with sub-projects which acted as tiers. New developers would try to import classes from other tiers and then not understand why their code wasn't working. They did not realize these tiers were more physically separated and couldn't be cross called at all times. There were certain reasons that the tiers could even be imported like this and they weren't fully disabled. So I used a banned list to help prevent crossing tiers where it wasn't appropriate. I actually think there is a 3rd reason, which is the more main reason, for this type of check. This check seems to be more centered around banning concrete classes and force the user to use the interfaces instead. The types it bans by default are all classes of Sets and Maps. Most times it doesn't matter the exact instance you are using, they all extend the same interfaces. There are checks enforce looser types like when passing a parameter to a method. If you specify
I think ImportControl would be better for these as I mentioned above. You can still instantiate the class with
Agree, we can't be creating a class and have a library be using that class at the same time. One has to come first, the library or the project we are in. ===== I am actually the opposite of @nrmancuso . I think we shouldn't violate these. We aren't declaring this as a type of something. We are just saying a banned type is allowed to extend the sealed class. We won't ban the instantiation of the banned type as shown above. It just can't be used as the declared type. In this scenario, this means users should be doing If we were to violate things, it seems to make more sense to violate the declaration of the banned class ( https://docs.oracle.com/javase/specs/jls/se22/html/jls-8.html#jls-8.1.6 - I am leaning towards not approving this, but I am not against it being approved. I think if we did approve this, we definitely need a way to enable/disable this since we are not 100% sure on this. This may depend more on what the user is implying by specifying a type that appears in this situation. We could also get input from a 3rd person. |
Let's allow this one to simmer for awhile, and let users get more familiar with this syntax and develop some opinions about it. If there is no clear cut path forward now, let's not push it. |
child of #14969
I have read check documentation: https://checkstyle.org/checks/coding/illegaltype.html#IllegalType
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Describe what you expect in detail.
violation on the Illegal classes in the permitted list
The text was updated successfully, but these errors were encountered: