jdk/test/javax/xml/bind/JAXBContext/JAXBContextWithSubclassedFactory.java
author dfuchs
Fri, 24 Jun 2016 16:03:17 +0100
changeset 39152 ab6a58b6301d
child 40261 86a49ba76f52
permissions -rw-r--r--
8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation Summary: trivial fix - the concrete class must be instantiated, not the class that defines the createContext method. Reviewed-by: lancea, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39152
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     1
/*
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     4
 *
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     8
 *
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    14
 *
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    18
 *
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    21
 * questions.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    22
 */
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    23
import java.security.Permission;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    24
import java.security.Policy;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    25
import java.security.ProtectionDomain;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    26
import java.util.Map;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    27
import javax.xml.bind.JAXBContext;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    28
import javax.xml.bind.JAXBContextFactory;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    29
import javax.xml.bind.JAXBException;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    30
import javax.xml.bind.Marshaller;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    31
import javax.xml.bind.Unmarshaller;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    32
import javax.xml.bind.Validator;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    33
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    34
/**
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    35
 * @test
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    36
 * @bug 8150173
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    37
 * @summary Verifies that a factory which inherit its createContext method
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    38
 *          from a concrete subclass of JAXBContextFactory is be instantiated.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    39
 * @compile -addmods java.xml.bind JAXBContextWithSubclassedFactory.java
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    40
 * @run main/othervm -addmods java.xml.bind JAXBContextWithSubclassedFactory
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    41
 */
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    42
public class JAXBContextWithSubclassedFactory {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    43
    static JAXBContext tmp;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    44
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    45
    public static class JAXBContextImpl extends JAXBContext {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    46
        public final Class<?> creator;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    47
        JAXBContextImpl(Class<?> creator) {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    48
            this.creator = creator;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    49
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    50
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    51
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    52
        public Unmarshaller createUnmarshaller() throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    53
            return tmp.createUnmarshaller();
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    54
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    55
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    56
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    57
        public Marshaller createMarshaller() throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    58
            return tmp.createMarshaller();
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    59
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    60
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    61
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    62
        public Validator createValidator() throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    63
            return tmp.createValidator();
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    64
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    65
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    66
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    67
    public static class FactoryBase implements JAXBContextFactory {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    68
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    69
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    70
        public JAXBContext createContext(Class<?>[] classesToBeBound,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    71
                Map<String, ?> properties) throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    72
            return new JAXBContextImpl(this.getClass());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    73
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    74
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    75
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    76
        public JAXBContext createContext(String contextPath,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    77
                ClassLoader classLoader, Map<String, ?> properties)
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    78
                throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    79
            return new JAXBContextImpl(this.getClass());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    80
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    81
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    82
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    83
    public static class NonFactoryBase {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    84
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    85
        public JAXBContext createContext(Class<?>[] classesToBeBound,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    86
                Map<String, ?> properties) throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    87
            return new JAXBContextImpl(this.getClass());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    88
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    89
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    90
        public JAXBContext createContext(String contextPath,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    91
                ClassLoader classLoader, Map<String, ?> properties)
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    92
                throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    93
            return new JAXBContextImpl(this.getClass());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    94
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    95
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    96
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    97
    public static class Factory1 extends FactoryBase {}
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    98
    public static class Factory2 extends NonFactoryBase implements JAXBContextFactory {}
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    99
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   100
    // test both without and then with a security manager as the code path
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   101
    // can be different when System.getSecurityManager() != null;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   102
    public static void main(String[] args) throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   103
        System.out.println("\nWithout security manager\n");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   104
        test(FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   105
        test(Factory1.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   106
        test(Factory2.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   107
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   108
        System.out.println("\nWith security manager\n");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   109
        Policy.setPolicy(new Policy() {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   110
            @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   111
            public boolean implies(ProtectionDomain domain, Permission permission) {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   112
                return true; // allow all
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   113
            }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   114
        });
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   115
        System.setSecurityManager(new SecurityManager());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   116
        test(FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   117
        test(Factory1.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   118
        test(Factory2.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   119
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   120
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   121
    public static void test(Class<?> factoryClass) throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   122
        System.clearProperty(JAXBContext.JAXB_CONTEXT_FACTORY);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   123
        System.out.println("** Testing  with Factory Class: " + factoryClass.getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   124
        System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   125
                + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY, ""));
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   126
        System.out.println("Calling "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   127
                + "JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class)");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   128
        tmp = JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   129
        System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY,
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   130
                factoryClass.getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   131
        System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   132
                + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY));
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   133
        System.out.println("Calling "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   134
                + "JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class)");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   135
        JAXBContext ctxt = JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   136
        System.out.println("Successfully loaded JAXBcontext: " +
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   137
                System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   138
        if (ctxt.getClass() != JAXBContextImpl.class) {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   139
            throw new RuntimeException("Wrong JAXBContext class"
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   140
                + "\n\texpected: "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   141
                + System.identityHashCode(tmp) + "@" + JAXBContextImpl.class.getName()
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   142
                + "\n\tactual:   "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   143
                + System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   144
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   145
        if (((JAXBContextImpl)ctxt).creator != factoryClass) {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   146
            throw new RuntimeException("Wrong Factory class"
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   147
                + "\n\texpected: "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   148
                + System.identityHashCode(tmp) + "@" + factoryClass.getName()
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   149
                + "\n\tactual:   "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   150
                + System.identityHashCode(ctxt) + "@" + ((JAXBContextImpl)ctxt).creator.getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   151
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   152
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   153
}