How intelligent are the compilers?

I've got some lines of code like this:public Connection getConnection()throws SQLException

{

if ((iv_connection ==null) || (iv_connection.isClosed()))// !!!!!!!!

{

iv_connection = connect(iv_DBUser, iv_DBPasswort, iv_DBName);

iv_connection.setAutoCommit(false);

}

return iv_connection;

}

The problem is the if-clause. If the property iv_connection is null the rest of the clause does not have to be tested. But if it would be tested I would get a NullPointerException. The Webgain (Visual Cafe) compiler does a good job and the second part of the if-clause is not tested. But do all the other compilers do this too? I would like to be sure if the code is ok.

koem

[1095 byte] By [koem] at [2007-9-26 8:23:53]
# 1
the answer is here: http://forum.java.sun.com/thread.jsp?forum=4&thread=175844
koem at 2007-7-1 18:59:28 > top of Java-index,Developer Tools,Java Compiler...
# 2

You are right. All compilers should not evaluate the 2nd part of the statement if the first part is false. This is standard logic for an 'or' statement/gate. The compiler only need one false to evaluate false, it gets it on the first expression.

I would not expect any compiler to reach the 2nd statement in the case of 1st statement bieng false.

unless written by a student/consultant/etc. lol

itspike at 2007-7-1 18:59:28 > top of Java-index,Developer Tools,Java Compiler...