Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK24 remove System.getSecurityManager part 2 #21002

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ public boolean isVerbose() {
*/
@Override
public void setVerbose(boolean value) {
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
this.setVerboseImpl(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar17]*/
/*[INCLUDE-IF JAVA_SPEC_VERSION < 24]*/
/*
* Copyright IBM Corp. and others 2015
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,65 +432,6 @@ public static TabularData toSystemPropertiesTabularData(Map<String, String> prop
return result;
}

/**
* Convenience method that sets out to return the {@link Class} object for
* the specified type named <code>name</code>. Unlike the
* {@link Class#forName(java.lang.String)} method, this will work even for
* primitive types.
*
* @param name
* the name of a Java type
* @return the <code>Class</code> object for the type <code>name</code>
* @throws ClassNotFoundException
* if <code>name</code> does not correspond to any known type
* (including primitive types).
*/
public static Class<?> getClassMaybePrimitive(String name) throws ClassNotFoundException {
int i = name.lastIndexOf('.');

if (i != -1) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPackageAccess(name.substring(0, i));
}
}

Class<?> result = null;

try {
result = Class.forName(name);
} catch (ClassNotFoundException e) {
if (name.equals(boolean.class.getName())) {
result = boolean.class;
} else if (name.equals(char.class.getName())) {
result = char.class;
} else if (name.equals(byte.class.getName())) {
result = byte.class;
} else if (name.equals(short.class.getName())) {
result = short.class;
} else if (name.equals(int.class.getName())) {
result = int.class;
} else if (name.equals(long.class.getName())) {
result = long.class;
} else if (name.equals(float.class.getName())) {
result = float.class;
} else if (name.equals(double.class.getName())) {
result = double.class;
} else if (name.equals(void.class.getName())) {
result = void.class;
} else {
if (ManagementUtils.VERBOSE_MODE) {
e.printStackTrace(System.err);
}
// Rethrow the original ClassNotFoundException
throw e;
}
}

return result;
}

/**
* Convenience method to determine if the <code>wrapper</code>
* <code>Class</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,13 @@ public boolean isVerbose() {
*/
@Override
public void setVerbose(boolean value) {
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
theresa-m marked this conversation as resolved.
Show resolved Hide resolved
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
this.setVerboseImpl(value);
}

Expand Down Expand Up @@ -526,11 +528,13 @@ public void setMaxHeapSize(long size) {
if (size < this.getMinHeapSize() || size > this.getMaxHeapSizeLimit()) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
this.setMaxHeapSizeImpl(size);
}

Expand Down Expand Up @@ -662,11 +666,13 @@ public boolean setSharedClassCacheSoftmxBytes(long value) {
if (value < 0) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return this.setSharedClassCacheSoftmxBytesImpl(value);
}

Expand All @@ -677,11 +683,13 @@ public boolean setSharedClassCacheMinAotBytes(long value) {
if (value < 0) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return this.setSharedClassCacheMinAotBytesImpl(value);
}

Expand All @@ -692,11 +700,13 @@ public boolean setSharedClassCacheMaxAotBytes(long value) {
if (value < 0) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return this.setSharedClassCacheMaxAotBytesImpl(value);
}

Expand All @@ -707,11 +717,13 @@ public boolean setSharedClassCacheMinJitDataBytes(long value) {
if (value < 0) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return this.setSharedClassCacheMinJitDataBytesImpl(value);
}

Expand All @@ -722,11 +734,13 @@ public boolean setSharedClassCacheMaxJitDataBytes(long value) {
if (value < 0) {
throw new IllegalArgumentException();
}
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return this.setSharedClassCacheMaxJitDataBytesImpl(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,13 @@ public boolean isValid() {
*/
@Override
public void resetPeakUsage() {
/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
this.resetPeakUsageImpl(id);
}

Expand All @@ -386,11 +388,13 @@ public void setCollectionUsageThreshold(long threshold) {
throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K05EE")); //$NON-NLS-1$
}

/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

if (threshold < 0) {
/*[MSG "K05FE", "Collection usage threshold cannot be negative."]*/
Expand Down Expand Up @@ -421,11 +425,13 @@ public void setUsageThreshold(long threshold) {
throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K05EF")); //$NON-NLS-1$
}

/*[IF JAVA_SPEC_VERSION < 24]*/
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(ManagementPermissionHelper.MPCONTROL);
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

if (threshold < 0) {
/*[MSG "K05F0", "Usage threshold cannot be negative."]*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public final String getBootClassPath() {
throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K05F5")); //$NON-NLS-1$
}

/*[IF JAVA_SPEC_VERSION < 24]*/
checkMonitorPermission();
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return VM.internalGetProperties().getProperty("sun.boot.class.path"); //$NON-NLS-1$
}

Expand Down Expand Up @@ -208,7 +210,9 @@ public final boolean isBootClassPathSupported() {
*/
@Override
public final List<String> getInputArguments() {
/*[IF JAVA_SPEC_VERSION < 24]*/
checkMonitorPermission();
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
return Collections.unmodifiableList(ManagementUtils.convertStringArrayToList(VM.getVMArgs()));
}

Expand Down Expand Up @@ -237,6 +241,7 @@ public final ObjectName getObjectName() {
return objectName;
}

/*[IF JAVA_SPEC_VERSION < 24]*/
public static void checkMonitorPermission() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
Expand All @@ -245,5 +250,6 @@ public static void checkMonitorPermission() {
security.checkPermission(ManagementPermissionHelper.MPMONITOR);
}
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

}
Loading