Bug 574499 - [16] [Sealed Classes] Error thrown for a class implementing a sealed super class should be more specific
Summary: [16] [Sealed Classes] Error thrown for a class implementing a sealed super cl...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Kalyan Prasad Tatavarthi CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 574526
  Show dependency tree
 
Reported: 2021-06-28 07:52 EDT by Kalyan Prasad Tatavarthi CLA
Modified: 2024-04-03 07:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kalyan Prasad Tatavarthi CLA 2021-06-28 07:52:38 EDT
Steps to reproduce.

1) Create a java project with  Java 16 compliance and previews enabled.(Do not create module-info.java)
2) Create 2 Packages Pkg1 and Pkg2
3) Create 2 classes Cls1 and Cls2 in Pkg1 such that Cls1 is a sealed class which permits Cls2 and Cls2 implements Cls1.
4) Create a class final Cls3 in Pkg2 and select Cls1 as its super class

An error is reported in Cls3 that Cls3 is not a permitted type of Cls1.

But adding Cls3 to permitted types of Cls1 does not fix the problem as this is a non-modular project and the classes are in different packages. So, In a non-modular project all sealed and permitted classes should belong to the same package.

An appropriate error needs to be thrown here that Cls3 cannot extend Cls1 as it is a sealed class in a different package.

Similarly if the project is modular, both Cls1 and Cls3 need to belong to same module. Appropriate error also needs to be thrown here.

Similarly if the sealed Super Class is coming from an external jar (read-only) then too an appropriate error needs to be thrown.
Comment 1 Kalyan Prasad Tatavarthi CLA 2021-06-28 07:54:47 EDT
(In reply to Kalyan Prasad Tatavarthi from comment #0)
> Steps to reproduce.
> 
> 1) Create a java project with  Java 16 compliance and previews enabled.(Do
> not create module-info.java)
> 2) Create 2 Packages Pkg1 and Pkg2
> 3) Create 2 classes Cls1 and Cls2 in Pkg1 such that Cls1 is a sealed class
> which permits Cls2 and Cls2 implements Cls1.
> 4) Create a class final Cls3 in Pkg2 and select Cls1 as its super class
> 
> An error is reported in Cls3 that Cls3 is not a permitted type of Cls1.
> 
> But adding Cls3 to permitted types of Cls1 does not fix the problem as this
> is a non-modular project and the classes are in different packages. So, In a
> non-modular project all sealed and permitted classes should belong to the
> same package.
> 
> An appropriate error needs to be thrown here that Cls3 cannot extend Cls1 as
> it is a sealed class in a different package.
> 
> Similarly if the project is modular, both Cls1 and Cls3 need to belong to
> same module. Appropriate error also needs to be thrown here.
> 
> Similarly if the sealed Super Class is coming from an external jar
> (read-only) then too an appropriate error needs to be thrown.

Correction: In a non-modular project a sealed and all its permitted classes should belong to the same package.
Comment 2 Eclipse Genie CLA 2021-06-29 02:57:41 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182572
Comment 4 Kalyan Prasad Tatavarthi CLA 2021-07-06 08:14:08 EDT
Creating a new sub class Cls4 with Cls1 as super class using the  "New Class Creation Wizard" reports error that Cls4 is in a different package even if they are in the same packages
Comment 5 Eclipse Genie CLA 2021-07-07 02:57:46 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/182833
Comment 7 Kalyan Prasad Tatavarthi CLA 2021-07-07 08:40:45 EDT
Keeping this bug open so as to figure out the issue that was happening in Comment 4 . The fix added now is only to not give a wrong error.
Comment 8 Eclipse Genie CLA 2024-04-03 07:37:54 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.