Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/jdk/internal/util/StaticProperty.java
41159 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.util;
27
28
import java.util.Properties;
29
30
/**
31
* System Property access for internal use only.
32
* Read-only access to System property values initialized during Phase 1
33
* are cached. Setting, clearing, or modifying the value using
34
* {@link System#setProperty) or {@link System#getProperties()} is ignored.
35
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
36
* in these access methods. The caller of these methods should take care to ensure
37
* that the returned property is not made accessible to untrusted code.</strong>
38
*/
39
public final class StaticProperty {
40
41
// The class static initialization is triggered to initialize these final
42
// fields during init Phase 1 and before a security manager is set.
43
private static final String JAVA_HOME;
44
private static final String USER_HOME;
45
private static final String USER_DIR;
46
private static final String USER_NAME;
47
private static final String JAVA_LIBRARY_PATH;
48
private static final String SUN_BOOT_LIBRARY_PATH;
49
private static final String JDK_SERIAL_FILTER;
50
private static final String JAVA_IO_TMPDIR;
51
private static final String NATIVE_ENCODING;
52
53
private StaticProperty() {}
54
55
static {
56
Properties props = System.getProperties();
57
JAVA_HOME = getProperty(props, "java.home");
58
USER_HOME = getProperty(props, "user.home");
59
USER_DIR = getProperty(props, "user.dir");
60
USER_NAME = getProperty(props, "user.name");
61
JAVA_IO_TMPDIR = getProperty(props, "java.io.tmpdir");
62
JAVA_LIBRARY_PATH = getProperty(props, "java.library.path", "");
63
SUN_BOOT_LIBRARY_PATH = getProperty(props, "sun.boot.library.path", "");
64
JDK_SERIAL_FILTER = getProperty(props, "jdk.serialFilter", null);
65
NATIVE_ENCODING = getProperty(props, "native.encoding");
66
}
67
68
private static String getProperty(Properties props, String key) {
69
String v = props.getProperty(key);
70
if (v == null) {
71
throw new InternalError("null property: " + key);
72
}
73
return v;
74
}
75
76
private static String getProperty(Properties props, String key,
77
String defaultVal) {
78
String v = props.getProperty(key);
79
return (v == null) ? defaultVal : v;
80
}
81
82
/**
83
* Return the {@code java.home} system property.
84
*
85
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
86
* in this method. The caller of this method should take care to ensure
87
* that the returned property is not made accessible to untrusted code.</strong>
88
*
89
* @return the {@code java.home} system property
90
*/
91
public static String javaHome() {
92
return JAVA_HOME;
93
}
94
95
/**
96
* Return the {@code user.home} system property.
97
*
98
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
99
* in this method. The caller of this method should take care to ensure
100
* that the returned property is not made accessible to untrusted code.</strong>
101
*
102
* @return the {@code user.home} system property
103
*/
104
public static String userHome() {
105
return USER_HOME;
106
}
107
108
/**
109
* Return the {@code user.dir} system property.
110
*
111
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
112
* in this method. The caller of this method should take care to ensure
113
* that the returned property is not made accessible to untrusted code.</strong>
114
*
115
* @return the {@code user.dir} system property
116
*/
117
public static String userDir() {
118
return USER_DIR;
119
}
120
121
/**
122
* Return the {@code user.name} system property.
123
*
124
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
125
* in this method. The caller of this method should take care to ensure
126
* that the returned property is not made accessible to untrusted code.</strong>
127
*
128
* @return the {@code user.name} system property
129
*/
130
public static String userName() {
131
return USER_NAME;
132
}
133
134
/**
135
* Return the {@code java.library.path} system property.
136
*
137
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
138
* in this method. The caller of this method should take care to ensure
139
* that the returned property is not made accessible to untrusted code.</strong>
140
*
141
* @return the {@code java.library.path} system property
142
*/
143
public static String javaLibraryPath() {
144
return JAVA_LIBRARY_PATH;
145
}
146
147
/**
148
* Return the {@code java.io.tmpdir} system property.
149
*
150
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
151
* in this method. The caller of this method should take care to ensure
152
* that the returned property is not made accessible to untrusted code.</strong>
153
*
154
* @return the {@code java.io.tmpdir} system property
155
*/
156
public static String javaIoTmpDir() {
157
return JAVA_IO_TMPDIR;
158
}
159
160
/**
161
* Return the {@code sun.boot.library.path} system property.
162
*
163
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
164
* in this method. The caller of this method should take care to ensure
165
* that the returned property is not made accessible to untrusted code.</strong>
166
*
167
* @return the {@code sun.boot.library.path} system property
168
*/
169
public static String sunBootLibraryPath() {
170
return SUN_BOOT_LIBRARY_PATH;
171
}
172
173
174
/**
175
* Return the {@code jdk.serialFilter} system property.
176
*
177
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
178
* in this method. The caller of this method should take care to ensure
179
* that the returned property is not made accessible to untrusted code.</strong>
180
*
181
* @return the {@code jdk.serialFilter} system property
182
*/
183
public static String jdkSerialFilter() {
184
return JDK_SERIAL_FILTER;
185
}
186
187
/**
188
* Return the {@code native.encoding} system property.
189
*
190
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
191
* in this method. The caller of this method should take care to ensure
192
* that the returned property is not made accessible to untrusted code.</strong>
193
*
194
* @return the {@code native.encoding} system property
195
*/
196
public static String nativeEncoding() {
197
return NATIVE_ENCODING;
198
}
199
}
200
201