Bug 253085 - [recovery][compiler] Misleading error given in java on ternary operator
Summary: [recovery][compiler] Misleading error given in java on ternary operator
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-01 21:52 EDT by Zoe Gagnon CLA
Modified: 2022-11-17 14:29 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zoe Gagnon CLA 2008-11-01 21:52:56 EDT
When the ternary operator ( ?: ) is called with a void function as one of the last operands, the error given in the java perspective is:

No exception of type void can be thrown; an exception type must be a subclass of Throwable

This is misleading since the problem is one of a malformed statement (or not a statement at all), rather than anything obviously exception related.
Comment 1 Remy Suen CLA 2008-11-02 01:21:17 EST
This will show the problem:

public class Snippet {

	private static void voidA() { }

	private static void voidB() { }

	private static boolean b = false;

	public static void method() {
		int i = 0;
		switch(i) {
		case 0:
			b ? voidA() : voidB();
			break;
		}
	}
}
Comment 2 Philipe Mulet CLA 2008-11-03 05:19:26 EST
I agree this error is misleading. Note though that there was a primary syntax error reported just above:

	case 0:
	      ^
Syntax error on token ":", throw expected after this token

The misleading error is a secondary error induced by the statement recovery.
Comment 3 Philipe Mulet CLA 2008-11-03 05:23:16 EST
Statement recovery did produce a strange construction:

public static void method() {
  int i = 0;
  switch (i) {
  case 0 : ;
      throw (b ? voidA() : voidB());
      break ;
  }
}
Comment 4 Mike Wilson CLA 2009-05-05 12:08:23 EDT
Changing Version tag to something more believable.
Comment 5 Eclipse Genie CLA 2020-08-23 10:48:41 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.
Comment 6 Eclipse Genie CLA 2022-11-17 14:29:36 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.