RFR: 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in absract class extended by discovered JAXB implementation

Georgiy Rakov georgiy.rakov at oracle.com
Wed Jun 22 10:37:44 UTC 2016


On 21.06.2016 22:51, Mandy Chung wrote:
>> On Jun 21, 2016, at 10:39 AM, Daniel Fuchs <daniel.fuchs at oracle.com> wrote:
>>
>> Hi,
>>
>> Please find below a somewhat trivial patch for
>>
>> 8150173: JAXBContext.newInstance causes PrivilegedActionException
>>          when createContext's declared in absract class extended
>>          by discovered JAXB implementation
>> https://bugs.openjdk.java.net/browse/JDK-8150173
>>
>> Patch:
>> http://cr.openjdk.java.net/~dfuchs/webrev_8150173/webrev.00
>>
>> This is an oversight that was introduced with JDK-8145104.
>>
>> The issue is simply that newInstance() must be invoked on
>> the concrete class, not on the class that defines the
>> createContext method.
> Thanks for taking this one on.
>
>   234             if (JAXBContextFactory.class.isAssignableFrom(declaringClass)
>
> The spec says that implementation class of JAXBContextFactory must also implement no-arg constructor.
Line 234 seems to be even harmful for the following case:

public class FactoryBase {public JAXBContext createContext(Class<?>[] 
classesToBeBound, Map<String, ?> properties) throws JAXBException 
{...}public JAXBContext createContext(String contextPath, ClassLoader 
classLoader, Map<String, ?> properties) throws JAXBException 
{...}}public class Factory extends FactoryBase implements 
JAXBContextFactory { }Please also see attached minimal testcase.

Georgiy
>
> So I think this line is not needed.  Instead instantiateProviderIfNecessary should simply take the implClass parameter (the Method parameter doesn’t seem to be needed).
>
>   245             throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, declaringClass, e), e);
>
> Since you are on this file, it looks to me that it should use e.getCause() instead of e.
>
> Mandy
>

-------------- next part --------------
/*
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
 */

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBContextFactory;
import javax.xml.bind.JAXBException;
import java.util.Map;

/**
 * @author Georgiy Rakov
 */
public class Test9 {
    private static JAXBContext tmp;

    public static class FactoryBase {
        public JAXBContext createContext(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException {
            return tmp;
        }

        public JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
                throws JAXBException {
            return tmp;
        }
    }

    public static class Factory extends FactoryBase implements JAXBContextFactory {
    }

    public static void main(String[] args) throws JAXBException {
        tmp = JAXBContext.newInstance(Test9.class);
        System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "Test9$Factory");
        JAXBContext.newInstance(Test9.class);
    }
}


More information about the core-libs-dev mailing list