Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343738

Summary: [1.5][compiler] Enum constructor that throws Exception could report a better message
Product: [Eclipse Project] JDT Reporter: Satyam Kandula <satyam.kandula>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann, stephan.herrmann
Version: 3.7   
Target Milestone: 4.14 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Satyam Kandula CLA 2011-04-25 10:59:54 EDT
This is a FUP of bug 340029. Though the message has improved with bug 340029, It can be further improved. 

Compiling the following code:
public enum X {
  A, B;
  private X() throws Exception {
  }
}
reports error at A, B. 
Ideally the error should be reported at X.
Comment 1 Olivier Thomann CLA 2011-04-25 11:03:16 EDT
When you have no constructor, where would you report the error message ?
Comment 2 Satyam Kandula CLA 2011-04-25 11:26:49 EDT
(In reply to comment #1)
> When you have no constructor, where would you report the error message ?
Then there is no exception. If enum values have a constructor which throws an exception, we do give a message at throws itself.
Comment 3 Olivier Thomann CLA 2011-08-16 15:47:04 EDT
The way these errors are reported means that we would end up with two errors reported on the constructor declaration in this case.
We could potentially get as many errors reported against the constructor declarations as the number of enum constants.
Is this really what you want?
Comment 4 Eclipse Genie CLA 2019-12-04 18:40:34 EST
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.
Comment 5 Stephan Herrmann CLA 2019-12-05 03:34:57 EST
I think the existing error reporting is fine. If multiple enum constructors are defined, individual enum constants have the option to invoke a non-throwing constructor and thus would be clean. Ergo: only when looking at an enum constant we can decide whether or not to raise the error.

Example:
//----
public enum X {
  A, B,
  C(1) ;
  private X() throws Exception {
  }
  private X(int i) {}
}
//----


ecj reports:
----------
1. ERROR in /tmp/X.java (at line 2)
        A, B,
        ^
Unhandled exception type Exception
----------
2. ERROR in /tmp/X.java (at line 2)
        A, B,
           ^
Unhandled exception type Exception
----------
2 problems (2 errors)

i.e., we remain silent about C(1), which is correct. If all enum constants use the 2nd constructor, the only complaint would be about an unused constructor.