Skip to content

Commit

Permalink
Prevent Jackson failing while loading Modules (classloader issues)
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and senivam committed Apr 12, 2024
1 parent 9c5b688 commit 74781a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -31,6 +31,7 @@

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -99,7 +100,14 @@ private List<Module> filterModules() {
commonConfig.getRuntimeType(),
CommonProperties.JSON_JACKSON_ENABLED_MODULES, String.class);

final List<Module> modules = ObjectMapper.findModules();
final List<Module> modules;
try {
modules = ObjectMapper.findModules();
} catch (Exception e) {
LOGGER.warning(LocalizationMessages.ERROR_MODULES_NOT_LOADED(e.getMessage()));
return Collections.emptyList();
}

modules.removeIf(mod -> mod.getModuleName().contains(EXCLUDE_MODULE_NAME));

if (enabledModules != null && !enabledModules.isEmpty()) {
Expand Down
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -14,4 +14,5 @@
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
#

error.jackson.streamreadconstraints=Error setting StreamReadConstraints: {0}. Possibly not Jackson 2.15?
error.jackson.streamreadconstraints=Error setting StreamReadConstraints: {0}. Possibly not Jackson 2.15?
error.modules.not.loaded=Jackson modules could not be loaded: {0}

0 comments on commit 74781a9

Please sign in to comment.