Skip to content

Commit

Permalink
throw runtimeex instead of NPE if there is not impl found
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Dec 1, 2021
1 parent bece214 commit 8ba9aee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions api/src/main/java/jakarta/activation/FactoryFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RuntimeException createException(Throwable throwable, String message) {
* that there is no default class name
* @param tryFallback whether to try the default class as a
* fallback
* @exception RuntimeException if there is a SOAP error
* @exception RuntimeException if there is no factory found
*/
static <T> T find(Class<T> factoryClass,
String defaultClassName,
Expand Down Expand Up @@ -85,9 +85,11 @@ static <T> T find(Class<T> factoryClass,
}
}

// If not found and fallback should not be tried, return a null result.
if (!tryFallback)
return null;
// If not found and fallback should not be tried, throw RuntimeException.
if (!tryFallback) {
throw new RuntimeException(
"Provider for " + factoryId + " cannot be found", null);
}

// We didn't find the class through the usual means so try the default
// (built in) factory if specified.
Expand Down

0 comments on commit 8ba9aee

Please sign in to comment.