Bug 331281 - Misleading error displayed
Summary: Misleading error displayed
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-28 06:15 EST by Jonathan Camilleri CLA
Modified: 2010-12-07 04:00 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Camilleri CLA 2010-11-28 06:15:16 EST
Build Identifier: 20100917-0705

Consider the following code snippet which has a syntax error at line 19:

import java.math.*;
import java.util.Arrays;

public class Welcome {

	/**
	 * This program is a dummy program.
	 */
	public static void main(String[] args) {
	   
	int[] a = {1, 2, 3, 4, 5};
	
	for (int i = 0; i < 5; i++)
	{
		a[i] = i;
		System.out.println("The value of a[" + i + "] is:" + i);
	}
	
//BUGGY	int[] a_clone  Arrays.copyOf(a, a.length);
//should read   int[] a_clone = Arrays.copyOf(a, a.length);

	for (int i = 0; i < 5; i++)
	{
		a_clone [i] = i;
		System.out.println("The value of a_clone [" + i + "] is:" + i);
	}
	
	
	}
	

}

When compiling the error displayed reads, as follows, and, this is misleading, because the code snippet is already terminated with a semicolon(;).
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	Syntax error, insert ";" to complete LocalVariableDeclarationStatement

	at Welcome.main(Welcome.java:19)

It would also be suggested, to have the following features within the Debug perspective:
1. Step through the code line by line using shortcut keys
2. Step over a particular (e.g. buggy) line of code to view the effect on the other variables when that line or group of lines is not executed.

Similar features are available within Visual Studio 2008, and, possibly within Visual Studio 2010.

Reproducible: Always

Steps to Reproduce:
See details
Comment 1 Remy Suen CLA 2010-11-28 06:26:55 EST
(In reply to comment #0)
> It would also be suggested, to have the following features within the Debug
> perspective:
> 1. Step through the code line by line using shortcut keys

Can't you already do that with F5, F6, and F7?

> 2. Step over a particular (e.g. buggy) line of code to view the effect on the
> other variables when that line or group of lines is not executed.

See bug 163831.

When you have multiple items to report, you should open multiple bugs instead of grouping them all into one, by the way.
Comment 2 Stephan Herrmann CLA 2010-11-28 12:25:45 EST
(In reply to comment #0)
> When compiling the error displayed reads, as follows, and, this is misleading,
> because the code snippet is already terminated with a semicolon(;).
> Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
>     Syntax error, insert ";" to complete LocalVariableDeclarationStatement
> 
>     at Welcome.main(Welcome.java:19)

In the editor the error is associated only to the name "a_clone"
not the whole line. In that context the message is correct, because
there is no ";" after "a_clone" and inserting one fixes the syntax error.

This is only misleading when you *run* the buggy program, because then you
get the error message without precise context. But going back to the editor
you should see where exactly the compiler complains.
Isn't that sufficient?
Comment 3 Ayushman Jain CLA 2010-11-29 01:19:53 EST
(In reply to comment #2)
> [..]
> In the editor the error is associated only to the name "a_clone"
> not the whole line. In that context the message is correct, because
> there is no ";" after "a_clone" and inserting one fixes the syntax error.

I agree. This is a legitimate error because inserting a ';' after a_clone would result in a valid local variable declaration statement. This is exactly what the compiler is trying to tell you.
Comment 4 Dani Megert CLA 2010-11-29 03:57:19 EST
The issued message is correct and the same as 'javac' issues.
Comment 5 Satyam Kandula CLA 2010-12-07 04:00:23 EST
Verified for 3.7M4