Skip to content

Commit

Permalink
Make sure providers get only properties they are required to understand
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Aug 28, 2023
1 parent 66b10a6 commit 4f2ab0e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions api/src/main/java/jakarta/xml/bind/ContextFinder.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,21 +10,19 @@

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;
import java.security.AccessController;
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;


/**
Expand Down Expand Up @@ -356,7 +354,14 @@ static JAXBContext find(Class<?>[] classes, Map<String, ?> 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<String, ?> 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);
}
}

Expand Down

0 comments on commit 4f2ab0e

Please sign in to comment.