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 242212 - Erroneous hint: Throwable method result is ignored
Summary: Erroneous hint: Throwable method result is ignored
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:
Depends on:
Blocks:
 
Reported: 2014-02-22 05:07 UTC by _ gtzabari
Modified: 2015-05-15 14:26 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 _ gtzabari 2014-02-22 05:07:07 UTC
Product Version: NetBeans IDE Dev (Build 201402190001)
Java: 1.8.0-ea; Java HotSpot(TM) 64-Bit Server VM 25.0-b66
Runtime: Java(TM) SE Runtime Environment 1.8.0-ea-b124
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

Given:

public class JavaApplication2 {
    public static void main(String[] args) {
        try {
            System.out.println("foo");
        } catch (RuntimeException e) {
            throw new RuntimeException(e.getCause());
        }
    }
}

Netbeans flags the line with e.getCause() with "Throwable method result is ignored" when in fact the result is not ignored.
Comment 1 josephcz 2014-03-06 23:26:24 UTC
Another example seen in Build 201401141042 on Linux:

The use of the value returned from Throwable.getCause() produces a warning in foo() below which prints it out with a .toString() call, but simply printing it out in bar() (which uses the .toString() within println(..)) does not.

  @SuppressWarnings("UseOfSystemOutOrSystemErr")
  public static Object foo (java.lang.reflect.Method m) {
    try {
      return m.invoke(null);
    }
    catch (InvocationTargetException t) {
      System.err.println(t.getCause().toString()); // <-- Throwable method result is ignored
      System.exit(-1);
      return null;
    }
    catch (IllegalAccessException t) {
      return null;
    }
  }

  @SuppressWarnings("UseOfSystemOutOrSystemErr")
  public static Object bar (java.lang.reflect.Method m) {
    try {
      return m.invoke(null);
    }
    catch (InvocationTargetException t) {
      System.err.println(t.getCause()); // <-- No hint
      System.exit(-1);
      return null;
    }
    catch (IllegalAccessException t) {
      return null;
    }
  }
Comment 2 Svata Dedic 2014-03-07 12:22:11 UTC
fixed in jet-main#cdaa213ec845
Comment 3 Quality Engineering 2014-03-15 06:07:43 UTC
Integrated into 'main-silver', will be available in build *201403150001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/cdaa213ec845
User: Svata Dedic <sdedic@netbeans.org>
Log: #242212: detection of throwable usage improved
Comment 4 achirizzi 2015-04-17 15:20:40 UTC
This problem is still present in version 8.0.2


Product Version = NetBeans IDE 8.0.2 (Build 201411181905)
Operating System = Mac OS X version 10.10.2 running on x86_64
Java; VM; Vendor = 1.7.0_67
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.65-b04



  try {
    // ... throw new OrmException("example");
  } catch (OrmException maybeSqlTransactionRollbackException) {
   Throwable cause = maybeSqlTransactionRollbackException.getCause(); // <--- Erroneous hint here
   if (ChangesOnSlave.retryOnDeadlocks 
      && (cause instanceof SQLTransactionRollbackException)) {
      // ...
   } else {
     throw maybeSqlTransactionRollbackException;
   }
  }

NetBeans will still say that the cause is ignored even if it's used in the following if
Comment 5 _ gtzabari 2015-04-17 15:46:45 UTC
(In reply to achirizzi from comment #4)
> This problem is still present in version 8.0.2

I suggest opening a separate issue because the Affected Version is different. It could very well be that this was fixed in 8.0.1 and a regression in 8.0.2. Either way, 8.0.1 was already released.
Comment 6 achirizzi 2015-04-20 13:03:35 UTC
Opened bug 251944.

Thanks
Comment 7 Svata Dedic 2015-05-15 14:26:04 UTC
Setting back to fixed, the specific case was fixed as issue #251944