Make parent resource resolution more efficient by not relying on try/catch.

Description

In ResourceBundleResources the main resource lookup logic uses try/catch to return Optional.empty() if the requested string resource. The original idea was that missing resources would be infrequent, and if they were missing the overhead of catching an exception wouldn't be very bad as this was sort of an error condition to begin with.

What this approach didn't consider is that resources will be "missing" if they are defined in a parent Resources implementation. In a scenario in which a base class defines most resources, for example, it could actually be common for the subclass to fail to find resources and need to delegate to the parent Resources.

The solution would be in ResourceBundleResources.getOptionalStringImpl(String) to first ask the resource bundle if it has a resource for that key, and if not return an Optional.empty() without using try/catch. Nevertheless the try/catch block should still be present, and it wouldn't hurt for the catch block to also return Optional.empty() in the (unlikely and perhaps impossible) event that the resource was not available even though the resource bundle indicated that it was.

Thanks to Ed Erwin for pointing out this problem.

Environment

None

Assignee

Garret Wilson

Reporter

Garret Wilson

Labels

None

Components

Fix versions

Priority

Major
Configure