Bug 49600 - Bad exception thrown by ProxyDirContext.lookup
Summary: Bad exception thrown by ProxyDirContext.lookup
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2010-07-16 05:38 UTC by Marc Guillemot
Modified: 2010-07-22 09:42 UTC (History)
0 users

Unit tests illustrating the problems (3.17 KB, text/java)
2010-07-16 05:38 UTC, Marc Guillemot

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Guillemot 2010-07-16 05:38:47 UTC
Created attachment 25766 [details]
Unit tests illustrating the problems

Two problems with exception thrown by ProxyDirContext.lookup

- ProxyDirContext.lookup throws notFoundException when the entry doesn't exist. notFoundException is a field and therefore initialized at ProxyDirContext creation.

The consequence is that the exception thrown contains a stacktrace that has nothing to do with the current execution stack. This makes difficult to find the root cause of a problem. If this is really an optimization (what is the gain), then what about making this field static?

- ProxyDirContext.lookup is not consistent: for the same call it may throw NamingException or NameNotFoundException depending whether the cache has been used or not.

Problems occur in Tomcat 6 and 7.
Comment 1 Mark Thomas 2010-07-21 14:05:57 UTC
The gain by using notFoundException is in GC. It prevents exception objects being created for resources that don't exist. I agree it could be static (final too).
Comment 2 Mark Thomas 2010-07-21 16:33:07 UTC
Thanks for the test case. I kept the "not Found" test (with a minor modification" but not the strack trace test.

The returned exceptions have been made consistent for 7.0.x and will be included in 7.0.1 onwards.
Comment 3 Marc Guillemot 2010-07-22 02:50:00 UTC
Can you explain why GC gain are considered at this special place in detriment of a correct exception? 

For me if GC gain is an argument, then there are so many other places in Tomcat where it should apply. This starts with the BaseDirContext.lookup that you've fixed to address the "not Found" point of this case.
Comment 4 Mark Thomas 2010-07-22 09:42:03 UTC
No, I didn't write the original code but I trust that Remy had a good reason for this particular optimisation.