Community
Participate
Working Groups
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.
Question to JCore: Could the compiler report this in one problem, instead of creating several ones with the same location?
*** Bug 23355 has been marked as a duplicate of this bug. ***
*** Bug 23356 has been marked as a duplicate of this bug. ***
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.
Back to jdt/ui
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.
implemented > 20021010