Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/share/classes/jdk/internal/util/StaticProperty.java
67760 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 JDK_SERIAL_FILTER_FACTORY;
51
private static final String JAVA_IO_TMPDIR;
52
private static final String NATIVE_ENCODING;
53
54
private StaticProperty() {}
55
56
static {
57
Properties props = System.getProperties();
58
JAVA_HOME = getProperty(props, "java.home");
59
USER_HOME = getProperty(props, "user.home");
60
USER_DIR = getProperty(props, "user.dir");
61
USER_NAME = getProperty(props, "user.name");
62
JAVA_IO_TMPDIR = getProperty(props, "java.io.tmpdir");
63
JAVA_LIBRARY_PATH = getProperty(props, "java.library.path", "");
64
SUN_BOOT_LIBRARY_PATH = getProperty(props, "sun.boot.library.path", "");
65
JDK_SERIAL_FILTER = getProperty(props, "jdk.serialFilter", null);
66
JDK_SERIAL_FILTER_FACTORY = getProperty(props, "jdk.serialFilterFactory", null);
67
NATIVE_ENCODING = getProperty(props, "native.encoding");
68
}
69
70
private static String getProperty(Properties props, String key) {
71
String v = props.getProperty(key);
72
if (v == null) {
73
throw new InternalError("null property: " + key);
74
}
75
return v;
76
}
77
78
private static String getProperty(Properties props, String key,
79
String defaultVal) {
80
String v = props.getProperty(key);
81
return (v == null) ? defaultVal : v;
82
}
83
84
/**
85
* Return the {@code java.home} system property.
86
*
87
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
88
* in this method. The caller of this method should take care to ensure
89
* that the returned property is not made accessible to untrusted code.</strong>
90
*
91
* @return the {@code java.home} system property
92
*/
93
public static String javaHome() {
94
return JAVA_HOME;
95
}
96
97
/**
98
* Return the {@code user.home} system property.
99
*
100
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
101
* in this method. The caller of this method should take care to ensure
102
* that the returned property is not made accessible to untrusted code.</strong>
103
*
104
* @return the {@code user.home} system property
105
*/
106
public static String userHome() {
107
return USER_HOME;
108
}
109
110
/**
111
* Return the {@code user.dir} system property.
112
*
113
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
114
* in this method. The caller of this method should take care to ensure
115
* that the returned property is not made accessible to untrusted code.</strong>
116
*
117
* @return the {@code user.dir} system property
118
*/
119
public static String userDir() {
120
return USER_DIR;
121
}
122
123
/**
124
* Return the {@code user.name} system property.
125
*
126
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
127
* in this method. The caller of this method should take care to ensure
128
* that the returned property is not made accessible to untrusted code.</strong>
129
*
130
* @return the {@code user.name} system property
131
*/
132
public static String userName() {
133
return USER_NAME;
134
}
135
136
/**
137
* Return the {@code java.library.path} system property.
138
*
139
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
140
* in this method. The caller of this method should take care to ensure
141
* that the returned property is not made accessible to untrusted code.</strong>
142
*
143
* @return the {@code java.library.path} system property
144
*/
145
public static String javaLibraryPath() {
146
return JAVA_LIBRARY_PATH;
147
}
148
149
/**
150
* Return the {@code java.io.tmpdir} system property.
151
*
152
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
153
* in this method. The caller of this method should take care to ensure
154
* that the returned property is not made accessible to untrusted code.</strong>
155
*
156
* @return the {@code java.io.tmpdir} system property
157
*/
158
public static String javaIoTmpDir() {
159
return JAVA_IO_TMPDIR;
160
}
161
162
/**
163
* Return the {@code sun.boot.library.path} system property.
164
*
165
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
166
* in this method. The caller of this method should take care to ensure
167
* that the returned property is not made accessible to untrusted code.</strong>
168
*
169
* @return the {@code sun.boot.library.path} system property
170
*/
171
public static String sunBootLibraryPath() {
172
return SUN_BOOT_LIBRARY_PATH;
173
}
174
175
176
/**
177
* Return the {@code jdk.serialFilter} system property.
178
*
179
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
180
* in this method. The caller of this method should take care to ensure
181
* that the returned property is not made accessible to untrusted code.</strong>
182
*
183
* @return the {@code jdk.serialFilter} system property
184
*/
185
public static String jdkSerialFilter() {
186
return JDK_SERIAL_FILTER;
187
}
188
189
190
/**
191
* Return the {@code jdk.serialFilterFactory} system property.
192
*
193
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
194
* in this method. The caller of this method should take care to ensure
195
* that the returned property is not made accessible to untrusted code.</strong>
196
*
197
* @return the {@code jdk.serialFilterFactory} system property
198
*/
199
public static String jdkSerialFilterFactory() {
200
return JDK_SERIAL_FILTER_FACTORY;
201
}
202
203
/**
204
* Return the {@code native.encoding} system property.
205
*
206
* <strong>{@link SecurityManager#checkPropertyAccess} is NOT checked
207
* in this method. The caller of this method should take care to ensure
208
* that the returned property is not made accessible to untrusted code.</strong>
209
*
210
* @return the {@code native.encoding} system property
211
*/
212
public static String nativeEncoding() {
213
return NATIVE_ENCODING;
214
}
215
}
216
217