
org.openeuler.sun.misc.SharedSecrets Maven / Gradle / Ivy
/*
* Copyright (c) 2021, Huawei Technologies Co., Ltd. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Huawei designates this
* particular file as subject to the "Classpath" exception as provided
* by Huawei in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please visit https://gitee.com/openeuler/bgmprovider if you need additional
* information or have any questions.
*/
package org.openeuler.sun.misc;
import sun.security.util.Debug;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
/**
* Different versions of jdk's SharedSecrets class are in different packages.
* jdk8 package name - sun.misc
* jdk11 package name - jdk.internal.misc
* jdk17 package name - jdk.internal.access
*
* The JavaNetAccess class in jdk8 does not exist in jdk11, but JavaNetInetAddressAccess is used instead.
* The package name of the class is also different, and the method of obtaining the instance of the class
* is also different.
* jdk8 package name - sun.misc
* jdk11 package name - jdk.internal.misc
* jdk17 package name - jdk.internal.access
*/
public class SharedSecrets {
private static final Debug debug = Debug.getInstance("compatible");
// Candidate SharedSecrets class
private static final String[] candidateSharedSecretsClassNames = new String[]{
"sun.misc.SharedSecrets",
"jdk.internal.misc.SharedSecrets",
"jdk.internal.access.SharedSecrets"
};
// Candidate JavaNetAccess class
private static final String[] candidateJavaNetAccessClassNames = new String[]{
"sun.misc.JavaNetAccess",
"jdk.internal.misc.JavaNetInetAddressAccess",
"jdk.internal.access.JavaNetInetAddressAccess"
};
// The getJavaNetAccess or getJavaNetInetAddressAccess method.
private static Method getJavaNetAccessMethod;
// The getOriginalHostName method.
private static Method getOriginalHostNameMethod;
static {
AccessController.doPrivileged(new PrivilegedAction