From 4f2ab0ec24ae2959c947fc8da2065f7caa617caa Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Wed, 23 Aug 2023 09:58:33 +0200 Subject: [PATCH] Make sure providers get only properties they are required to understand Signed-off-by: Lukas Jungmann --- .../java/jakarta/xml/bind/ContextFinder.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/jakarta/xml/bind/ContextFinder.java b/api/src/main/java/jakarta/xml/bind/ContextFinder.java index 15fffa4..10c995e 100644 --- a/api/src/main/java/jakarta/xml/bind/ContextFinder.java +++ b/api/src/main/java/jakarta/xml/bind/ContextFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023 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 @@ -10,8 +10,6 @@ package jakarta.xml.bind; -import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; @@ -19,12 +17,12 @@ import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.Iterator; import java.util.Map; -import java.util.Properties; +import java.util.function.Predicate; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; /** @@ -356,7 +354,14 @@ static JAXBContext find(Class[] classes, Map properties) throws JA } } if (factoryClassName != null) { - return newInstance(classes, properties, factoryClassName); + //Providers are not required to understand JAXB_CONTEXT_FACTORY property + //and they must throw a JAXBException if they see it, so we need to remove it + //from properties passed to them + Map props = properties.entrySet() + .stream() + .filter(Predicate.not(e -> JAXBContext.JAXB_CONTEXT_FACTORY.equals(e.getKey()))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + return newInstance(classes, props, factoryClassName); } }