jdk/test/javax/xml/bind/JAXBContext/JAXBContextWithLegacyFactory.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.JAXBException;
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.Marshaller;
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.Unmarshaller;
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.Validator;
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    32
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
 * @test
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    35
 * @bug 8150173
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    36
 * @summary Verifies that a JAXBContext can be created with a legacy
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    37
 *          factory class that has static createContext methods.
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    38
 * @compile -addmods java.xml.bind JAXBContextWithLegacyFactory.java
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    39
 * @run main/othervm -addmods java.xml.bind JAXBContextWithLegacyFactory
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    40
 */
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    41
public class JAXBContextWithLegacyFactory {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    42
    private 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
    43
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    44
        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
    45
        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
    46
        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
    47
            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
    48
        }
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
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    51
        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
    52
            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
    53
        }
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
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    56
        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
    57
            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
    58
        }
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
        @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    61
        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
    62
            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
    63
        }
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
    public static abstract class FactoryBase {
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 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
    68
                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
    69
            return new JAXBContextImpl(FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    70
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    71
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    72
        public static 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
    73
                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
    74
                throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    75
            return new JAXBContextImpl(FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    76
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    77
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    78
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    79
    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
    80
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    81
    public static class Factory2 extends FactoryBase {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    82
        public static 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
    83
                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
    84
            return new JAXBContextImpl(Factory2.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    85
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    86
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    87
        public static 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
    88
                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
    89
                throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    90
            return new JAXBContextImpl(Factory2.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    91
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    92
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    93
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    94
    // 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
    95
    // 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
    96
    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
    97
        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
    98
        test(FactoryBase.class, FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
    99
        test(Factory1.class, FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   100
        test(Factory2.class, Factory2.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   101
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   102
        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
   103
        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
   104
            @Override
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   105
            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
   106
                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
   107
            }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   108
        });
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   109
        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
   110
        test(FactoryBase.class, FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   111
        test(Factory1.class, FactoryBase.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   112
        test(Factory2.class, Factory2.class);
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
    public static void test(Class<?> factoryClass, Class<?> creatorClass) throws JAXBException {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   116
        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
   117
        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
   118
        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
   119
                + 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
   120
        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
   121
                + "JAXBContext.newInstance(JAXBContextWithLegacyFactory.class)");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   122
        tmp = JAXBContext.newInstance(JAXBContextWithLegacyFactory.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   123
        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
   124
                factoryClass.getName());
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   125
        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
   126
                + 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
   127
        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
   128
                + "JAXBContext.newInstance(JAXBContextWithLegacyFactory.class)");
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   129
        JAXBContext ctxt = JAXBContext.newInstance(JAXBContextWithLegacyFactory.class);
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   130
        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
   131
                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
   132
        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
   133
            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
   134
                + "\n\texpected: "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   135
                + 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
   136
                + "\n\tactual:   "
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
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   139
        if (((JAXBContextImpl)ctxt).creator != creatorClass) {
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   140
            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
   141
                + "\n\texpected: "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   142
                + System.identityHashCode(tmp) + "@" + creatorClass.getName()
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   143
                + "\n\tactual:   "
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   144
                + 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
   145
        }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   146
    }
ab6a58b6301d 8150173: JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation
dfuchs
parents:
diff changeset
   147
}