This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 199390 - multi-catch compiles inconsistently depending on what operations are performed
Summary: multi-catch compiles inconsistently depending on what operations are performed
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 7.0
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-14 01:06 UTC by stuart_marks
Modified: 2011-06-14 08:54 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description stuart_marks 2011-06-14 01:06:40 UTC
I'm using NetBeans 7 GA and I've configured it to use a recent build (b145)
of JDK 7. I've created a new project, configured it to use my JDK 7 platform,
and have set its source-level to 7. Enter the following code:

==========

import java.io.IOException;
import java.net.MalformedURLException;

public class MultiCatchTest {
    public static void main(String[] args) {
        try {
            if (args.length % 2 == 0)
                throw new IOException();
            else
                throw new MalformedURLException();
        } catch (MalformedURLException|IOException e) {
            // ...
        }
        System.out.println("hello");
    }
}

==========

This is illegal, and it should not run. However, the IDE does not
show an error (no red squiggly line), and it will succeed and
print "hello" if you choose the "Run" command. It will still
succeed if even if you choose "Clean" and then "Run". However, it will fail
(correctly) with the following error if you choose "Build" or "Clean And Build".

error: Alternatives in a multi-catch statement cannot be related by subclassing
        } catch (MalformedURLException|IOException e) {
  Alternative MalformedURLException is a subclass of alternative IOException

This inconsistent behavior disappears if "Compile On Save" is disabled in the 
project's properties.

As a user, I have to say that it is incredibly confusing to have "Clean and Build"
then "Run" behave radically different from "Clean" then "Run". This totally breaks
my mental model of what NetBeans is doing when you choose the Clean And Build, Clean,
Build, and Run commands.
Comment 1 Dusan Balek 2011-06-14 08:54:53 UTC
Should be fixed in the current dev build. Error is correctly shown in the recent builds.