Skip to content

Commit

Permalink
#224: ModelUtil error in JAXBContext.newInstance()
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Mar 15, 2022
1 parent 997005c commit 92b60b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
40 changes: 22 additions & 18 deletions api/src/main/java/jakarta/xml/bind/ContextFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,18 @@ static JAXBContext find(String factoryId,
String factoryName = classNameFromSystemProperties();
if (factoryName != null) return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties);

Object factory = properties.get(factoryId);
if (factory != null) {
if (factory instanceof String) {
factoryName = (String) factory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, factory.getClass().getName(), "String"));
if (properties != null) {
Object factory = properties.get(factoryId);
if (factory != null) {
if (factory instanceof String) {
factoryName = (String) factory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, factory.getClass().getName(), "String"));
}
}
if (factoryName != null) {
return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties);
}
}
if (factoryName != null) {
return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties);
}

JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader(
Expand Down Expand Up @@ -344,16 +346,18 @@ static JAXBContext find(Class<?>[] classes, Map<String, ?> properties) throws JA
String factoryClassName = classNameFromSystemProperties();
if (factoryClassName != null) return newInstance(classes, properties, factoryClassName);

Object ctxFactory = properties.get(JAXBContext.JAXB_CONTEXT_FACTORY);
if (ctxFactory != null) {
if (ctxFactory instanceof String) {
factoryClassName = (String) ctxFactory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, ctxFactory.getClass().getName(), "String"));
if (properties != null) {
Object ctxFactory = properties.get(JAXBContext.JAXB_CONTEXT_FACTORY);
if (ctxFactory != null) {
if (ctxFactory instanceof String) {
factoryClassName = (String) ctxFactory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, ctxFactory.getClass().getName(), "String"));
}
}
if (factoryClassName != null) {
return newInstance(classes, properties, factoryClassName);
}
}
if (factoryClassName != null) {
return newInstance(classes, properties, factoryClassName);
}

JAXBContextFactory factory =
Expand Down
10 changes: 9 additions & 1 deletion api/src/main/java/jakarta/xml/bind/ModuleUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -112,6 +112,14 @@ public static void delegateAddOpensToImplModule(Class<?>[] classes, Class<?> fac

Module jaxbModule = JAXBContext.class.getModule();

if (!jaxbModule.isNamed()) {
//we are not on the module path, so assume class-path mode
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Using jakarta.xml.bind-api on the class path.");
}
return;
}

for (Class<?> cls : classes) {
Class<?> jaxbClass = cls.isArray() ?
cls.getComponentType() : cls;
Expand Down

0 comments on commit 92b60b0

Please sign in to comment.