Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ lib
query.ser
datanucleus.txt
tck.txt
*.claude
6 changes: 3 additions & 3 deletions api/src/main/java/javax/jdo/LegacyJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static class SecurityManager {

public void checkPermission(JDOPermission permission) {
try {
checkPermissionMethod.invoke(null, permission);
checkPermissionMethod.invoke(sm, permission);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new JDOFatalInternalException(e.getMessage());
}
Expand All @@ -134,8 +134,8 @@ public void updateSecurityManager(Object sm) {
*/
private static boolean initIsSecurityDeprecated() {
try {
Method getSecurityManager = System.class.getMethod("getSecurityManager");
return getSecurityManager.isAnnotationPresent(Deprecated.class);
System.class.getMethod("getSecurityManager");
return false;
} catch (NoSuchMethodException e) {
return true;
}
Expand Down
66 changes: 66 additions & 0 deletions api/src/test/java/javax/jdo/LegacyJavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package javax.jdo;

import static org.junit.jupiter.api.Assertions.*;

import java.security.Permission;
import javax.jdo.spi.JDOImplHelper;
import javax.jdo.spi.JDOPermission;
import org.junit.jupiter.api.Test;

public class LegacyJavaTest {

@Test
public void testJDOImplHelper() {
// Try without security manager
assertNotNull(JDOImplHelper.getInstance());

if (LegacyJava.isSecurityManagerDeprecated()) {
return;
}
SecurityManager oldSecMgr = System.getSecurityManager();
try {
System.setSecurityManager(new MySecurityManager(JDOPermission.GET_METADATA));
} catch (UnsupportedOperationException e) {
// Running 24, SecurityManager is present but disabled by default.
return;
}

try {
// Try with security manager
assertThrows(JDOFatalInternalException.class, JDOImplHelper::getInstance);
} finally {
System.setSecurityManager(oldSecMgr);
}
}

public class MySecurityManager extends SecurityManager {
private final Permission invalidPermission;

public MySecurityManager(JDOPermission invalidPermission) {
this.invalidPermission = invalidPermission;
}

@Override
public void checkPermission(Permission perm) {
if (perm == invalidPermission)
throw new SecurityException("Permission not given: " + perm.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ private void closeWithMySecurityManager(PersistenceManagerFactory pmf) {
SecurityManager oldSecMgr = System.getSecurityManager();
try {
System.setSecurityManager(new MySecurityManager());
} catch (SecurityException se) {
// running with the TCK SecurityManager; don't run this test
} catch (SecurityException | UnsupportedOperationException se) {
// SecurityException: running with the TCK SecurityManager; don't run this test
// UnsupportedOperationException: running Java 24, SecurityManager is present but disabled
return;
}

Expand Down
Loading