Bug 20928 - "Add throws declaration" adds Exceptions multiple times
Summary: "Add throws declaration" adds Exceptions multiple times
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 23355 23356 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-06-24 21:12 EDT by Gary Gregory CLA
Modified: 2002-10-11 11:56 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Gregory CLA 2002-06-24 21:12:29 EDT
Build: eclipse-SDK-20020624-win32.zip. Windows 2000 SP2. 512MB RAM. 20GB HD.

In a Java method, add an API call that throws an uncaught Exception. 

1) For example:

<pre>
package com.seagullsw.unittest.io.xml;

import java.io.IOException;
import java.util.Arrays;

import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.security.c14n.CanonicalizationException;
import org.apache.xml.security.c14n.Canonicalizer;
import org.apache.xml.security.c14n.InvalidCanonicalizerException;
import org.xml.sax.SAXException;

/**
 * Requiremenrts:
 *
 * <code>org.apache.xml.security.c14n</code> classes from 
<code>http://xml.apache.org/security</code>.
 *
 */
public class XMLCanonicalizer {

	static String DEFAULT_ALGO_ID = 
Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;

	public static boolean canonicalEquals( String xml1, String xml2 ) {
			Canonicalizer c14n = Canonicalizer.getInstance( 
DEFAULT_ALGO_ID );
			byte[] c14nFromString = c14n.canonicalize( xml1.getBytes
() );
			byte[] c14nFromDom = c14n.canonicalize( xml2.getBytes
() );
			return Arrays.equals( c14nFromString, c14nFromDom );
	}

}
</pre>

2) Click on the first (topmost) red X icon in the margin, you get the 
suggestion to "Add throws declaration".

3) Accept the first suggestion and the 
Exception "InvalidCanonicalizerException" is added to the throws clause. Very 
nice.

4) The bug is that if you repeat set 2+3, you get the same exception added 
again and again.

Workaround: Do a File/Save, which compiles.

In the case where a line of code throws more than one Exception, like:

<pre>
byte[] c14nFromString = c14n.canonicalize( xml1.getBytes() );
</pre>

You MUST compile in order to be able to choose the next Exception to add to the 
list of throws.
Comment 1 Martin Aeschlimann CLA 2002-09-18 07:23:55 EDT
Question to JCore:
Could the compiler report this in one problem, instead of creating several ones 
with the same location?
Comment 2 Martin Aeschlimann CLA 2002-09-18 07:24:14 EDT
*** Bug 23355 has been marked as a duplicate of this bug. ***
Comment 3 Martin Aeschlimann CLA 2002-09-18 07:24:47 EDT
*** Bug 23356 has been marked as a duplicate of this bug. ***
Comment 4 Philipe Mulet CLA 2002-09-30 05:50:41 EDT
I wouldn't change the compiler error message, but rather have quickfix notice 
that several similar problems are reported for the same location.

Notice that currently the "surround with try catch" quickfix action does the 
right thing already.
Comment 5 Philipe Mulet CLA 2002-09-30 05:51:21 EDT
Back to jdt/ui
Comment 6 Martin Aeschlimann CLA 2002-09-30 08:03:41 EDT
It's quite some work for me to do this change. The surround with try/catch 
works different (it doesn't need the problems, it's the refactoring code 
analyzing statements to find uncaught exceptions).
I was hoping it's a trivial change on your side. 
Comment 7 Martin Aeschlimann CLA 2002-10-11 11:56:32 EDT
implemented > 20021010