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 239865 - Misleading "throwable method result is ignored" warning
Summary: Misleading "throwable method result is ignored" warning
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
: 241125 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-12-30 04:05 UTC by _ gtzabari
Modified: 2014-02-04 03:05 UTC (History)
1 user (show)

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 _ gtzabari 2013-12-30 04:05:10 UTC
Product Version: NetBeans IDE Dev (Build 201312230002)
Java: 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08
Runtime: Java(TM) SE Runtime Environment 1.7.0_45-b18
System: Windows 7 version 6.1 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Throwable.initCause() returns "this" but Netbeans warns "throwable method result is ignored" if the code ignores this return value. It is perfectly reasonable to ignore the result of initCause() and use the original exception object as follows:

catch (EntityNotFoundException e)
{
  NoSuchFileException e2 = new NoSuchFileException(null);
  e2.initCause(e);
  throw e2;
}

Expected behavior: Suppress this warning for Throwable.initCause().
Comment 1 _ gtzabari 2013-12-30 06:17:55 UTC
It looks like the hint is broken in a more general way. Given this code:

ConstraintViolationException constraintViolation = SQLExceptions.getConstraintViolation(e);
if (constraintViolation != null)
  throw new EntityExistsException(module.getName() + " " + version, e);
throw e;

Netbeans complaints that the result of "SQLExceptions.getConstraintViolation" is never used, but in fact it is used by the "if" statement.
Comment 2 Svata Dedic 2014-01-29 08:33:20 UTC
just a note: 'throwable method ignored' is a completely different hint than 'unused value'.
Comment 3 Svata Dedic 2014-01-29 12:44:31 UTC
Throwable.initCause is counted as 'valid' usage for the throwable as of jet-main#557e0d80c827


Please provide more complete code sample for issue #2 (unused assignment false warning). I've tried a more-or-less same code:

public class Test {
    public void test(Throwable e) {
        ConstraintViolationException constraintViolation = null;
        // some usage to suppress hint on variable decl
        if (constraintViolation != null) {}
        constraintViolation = SQLExceptions.getConstraintViolation(e);
        if (constraintViolation != null)
            throw new IllegalArgumentException("", e);
    }
}

but no hint appeared on the constraintViolation assingment. File a new defect, please.
Comment 4 Svata Dedic 2014-01-29 15:26:47 UTC
*** Bug 241125 has been marked as a duplicate of this bug. ***
Comment 5 Quality Engineering 2014-02-04 03:05:52 UTC
Integrated into 'main-silver', will be available in build *201402040001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/557e0d80c827
User: Svata Dedic <sdedic@netbeans.org>
Log: #239865: initCause counts as valid throwable usage