Project: Tomcat
Bug 52767 Potential Bug or Inconsistency in JDBCRealm.java and JDBCAccessLogValve.java
Reported: 2012-02-25 14:32:33 | Status: resolved fixed

This is Ken Cheung, a Computer Science M.Phil. student. I observed some code clones in Tomcat and found inconsistent code: /tomcat/trunk/java/org/apache/catalina/realm/JDBCRealm.java 676 if (driver == null) { 677 try { 678 Class<?> clazz = Class.forName(driverName); 679 driver = (Driver) clazz.newInstance(); 680 } catch (Throwable e) { 681 ExceptionUtils.handleThrowable(e); 682 throw new SQLException(e.getMessage(), e); 683 } 684 } 685 686 // Open a new connection 687 Properties props = new Properties(); 688 if (connectionName != null) 689 props.put("user", connectionName); 690 if (connectionPassword != null) 691 props.put("password", connectionPassword); 692 dbConnection = driver.connect(connectionURL, props); /tomcat/trunk/java/org/apache/catalina/valves/JDBCAccessLogValve.java 566 if (driver == null) { 567 try { 568 Class<?> clazz = Class.forName(driverName); 569 driver = (Driver) clazz.newInstance(); 570 } catch (Throwable e) { 571 ExceptionUtils.handleThrowable(e); 572 throw new SQLException(e.getMessage(), e); 573 } 574 } 575 576 // Open a new connection 577 Properties props = new Properties(); 578 props.put("autoReconnect", "true"); 579 if (connectionName != null) { 580 props.put("user", connectionName); 581 } 582 if (connectionPassword != null) { 583 props.put("password", connectionPassword); 584 } 585 conn = driver.connect(connectionURL, props); Quick description of the inconsistency Two code snippets are very similar code, but as you see, in JDBCRealm.java does not use "props.put("autoReconnect", "true")" while JDBCAccessLogValve.java has. We thought it could be a potential bug or inconsistency. Hope this helps.

Files changed in fix:
java/org/apache/catalina/valves/JDBCAccessLogValve.java