Bug 65347 - The equals method from statements generated by the StatementFacade throws both Illegal Argument Exception and NullPointerExceptions
Summary: The equals method from statements generated by the StatementFacade throws bot...
Status: NEW
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-02 12:08 UTC by Paul
Modified: 2021-06-02 12:09 UTC (History)
1 user (show)



Attachments
Unit test cases for the Statement Facade class (2.84 KB, text/plain)
2021-06-02 12:08 UTC, Paul
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul 2021-06-02 12:08:57 UTC
Created attachment 37885 [details]
Unit test cases for the Statement Facade class

tomcat-jdbc versions:  10.0.6 and 9.0.26

Statement objects created by the StatementFacade will throw exceptions from the equals method, if the provided comparison object is not a "java.lang.refelect.Proxy".  According to the javadoc for object this method should never throw and exception, but rather it should return false in those cases.
This becomes an issue when prepared statements are stored and retrieved from HashMaps and HashSets.

A proposed fix is to update the embedded StatementProxy.invoke() method with the following:
if (compare(EQUALS_VAL, method)) {
	try {
		Object rhs = args[0];
		if (rhs instanceof Proxy) {
			rhs = Proxy.getInvocationHandler(rhs);
		}
		return Boolean.valueOf(this.equals(rhs));
	} catch (Exception e) {
		return Boolean.FALSE;
	}
}

Also attached is a unit test.