java - Dead code warning in Eclipse - is this a bug in Eclipse? Or me overlooking something obvious? -



java - Dead code warning in Eclipse - is this a bug in Eclipse? Or me overlooking something obvious? -

with (simplified) code illustration eclipse (kepler sr2) gives warning innermost if-statement (if (con != null)), dead code.

public class dbmanager { public string getsinglestring(string query) throws sqlexception { dbmanager dbmgr = new dbmanager(); connection con = null; seek { con = dbmgr.getconnection("user", "pwd", url); } grab (classnotfoundexception e) { e.printstacktrace(); } grab (sqlexception e) { e.printstacktrace(); if (con != null) { preparedstatement pstmt = null; resultset rset = null; pstmt = con.preparestatement(query.tostring()); rset = pstmt.executequery(); if (rset != null && rset.next()) { homecoming (rset.getstring(1)); } } } homecoming null; }

typically database connection defined on line after seek create connection , offending if-statement true. warning dead code correct?

if connection created, grab statement never called dead code, seek rearranging to:

try { con = dbmgr.getconnection("user", "pwd", url); //if (con != null) { <-- not required because of seek , grab preparedstatement pstmt = null; resultset rset = null; pstmt = con.preparestatement(query.tostring()); rset = pstmt.executequery(); if (rset != null && rset.next()) { homecoming (rset.getstring(1)); } } grab (classnotfoundexception e) { e.printstacktrace(); } grab (sqlexception e) { e.printstacktrace(); }

java eclipse compiler-warnings suppress-warnings dead-code

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -