8301462: Convert Permission files to use lambda after JDK-8076596

Reviewed-by: jpai, dfuchs, mullan
This commit is contained in:
Mandy Chung 2023-02-08 19:06:41 +00:00
parent 8d4c76ddce
commit 10dd98d0dd
5 changed files with 61 additions and 94 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -1156,11 +1156,7 @@ final class FilePermissionCollection extends PermissionCollection
// Add permission to map if it is absent, or replace with new // Add permission to map if it is absent, or replace with new
// permission if applicable. // permission if applicable.
perms.merge(fp.getName(), fp, perms.merge(fp.getName(), fp, (existingVal, newVal) -> {
new java.util.function.BiFunction<>() {
@Override
public Permission apply(Permission existingVal,
Permission newVal) {
int oldMask = ((FilePermission)existingVal).getMask(); int oldMask = ((FilePermission)existingVal).getMask();
int newMask = ((FilePermission)newVal).getMask(); int newMask = ((FilePermission)newVal).getMask();
if (oldMask != newMask) { if (oldMask != newMask) {
@ -1169,13 +1165,11 @@ final class FilePermissionCollection extends PermissionCollection
return newVal; return newVal;
} }
if (effective != oldMask) { if (effective != oldMask) {
return ((FilePermission)newVal) return ((FilePermission)newVal).withNewActions(effective);
.withNewActions(effective);
} }
} }
return existingVal; return existingVal;
} }
}
); );
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -1383,13 +1383,8 @@ final class SocketPermissionCollection extends PermissionCollection
"attempt to add a Permission to a readonly PermissionCollection"); "attempt to add a Permission to a readonly PermissionCollection");
// Add permission to map if it is absent, or replace with new // Add permission to map if it is absent, or replace with new
// permission if applicable. NOTE: cannot use lambda for // permission if applicable.
// remappingFunction parameter until JDK-8076596 is fixed. perms.merge(sp.getName(), sp, (existingVal, newVal) -> {
perms.merge(sp.getName(), sp,
new java.util.function.BiFunction<>() {
@Override
public SocketPermission apply(SocketPermission existingVal,
SocketPermission newVal) {
int oldMask = existingVal.getMask(); int oldMask = existingVal.getMask();
int newMask = newVal.getMask(); int newMask = newVal.getMask();
if (oldMask != newMask) { if (oldMask != newMask) {
@ -1398,13 +1393,11 @@ final class SocketPermissionCollection extends PermissionCollection
return newVal; return newVal;
} }
if (effective != oldMask) { if (effective != oldMask) {
return new SocketPermission(sp.getName(), return new SocketPermission(sp.getName(), effective);
effective);
} }
} }
return existingVal; return existingVal;
} }
}
); );
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -79,16 +79,10 @@ implements java.io.Serializable
throw new IllegalArgumentException("invalid permission: "+ throw new IllegalArgumentException("invalid permission: "+
permission); permission);
// Add permission to map. NOTE: cannot use lambda for // Add permission to map.
// remappingFunction parameter until JDK-8076596 is fixed. perms.compute(unresolvedPermission.getName(), (key, oldValue) -> {
perms.compute(unresolvedPermission.getName(),
new java.util.function.BiFunction<>() {
@Override
public List<UnresolvedPermission> apply(String key,
List<UnresolvedPermission> oldValue) {
if (oldValue == null) { if (oldValue == null) {
List<UnresolvedPermission> v = List<UnresolvedPermission> v = new CopyOnWriteArrayList<>();
new CopyOnWriteArrayList<>();
v.add(unresolvedPermission); v.add(unresolvedPermission);
return v; return v;
} else { } else {
@ -96,7 +90,6 @@ implements java.io.Serializable
return oldValue; return oldValue;
} }
} }
}
); );
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -469,14 +469,8 @@ final class PropertyPermissionCollection extends PermissionCollection
String propName = pp.getName(); String propName = pp.getName();
// Add permission to map if it is absent, or replace with new // Add permission to map if it is absent, or replace with new
// permission if applicable. NOTE: cannot use lambda for // permission if applicable.
// remappingFunction parameter until JDK-8076596 is fixed. perms.merge(propName, pp, (existingVal, newVal) -> {
perms.merge(propName, pp,
new java.util.function.BiFunction<>() {
@Override
public PropertyPermission apply(PropertyPermission existingVal,
PropertyPermission newVal) {
int oldMask = existingVal.getMask(); int oldMask = existingVal.getMask();
int newMask = newVal.getMask(); int newMask = newVal.getMask();
if (oldMask != newMask) { if (oldMask != newMask) {
@ -490,7 +484,6 @@ final class PropertyPermissionCollection extends PermissionCollection
} }
return existingVal; return existingVal;
} }
}
); );
if (!all_allowed) { if (!all_allowed) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -567,13 +567,8 @@ final class KrbServicePermissionCollection extends PermissionCollection
String princName = sp.getName(); String princName = sp.getName();
// Add permission to map if it is absent, or replace with new // Add permission to map if it is absent, or replace with new
// permission if applicable. NOTE: cannot use lambda for // permission if applicable.
// remappingFunction parameter until JDK-8076596 is fixed. perms.merge(princName, sp, (existingVal, newVal) -> {
perms.merge(princName, sp,
new java.util.function.BiFunction<>() {
@Override
public Permission apply(Permission existingVal,
Permission newVal) {
int oldMask = ((ServicePermission) existingVal).getMask(); int oldMask = ((ServicePermission) existingVal).getMask();
int newMask = ((ServicePermission) newVal).getMask(); int newMask = ((ServicePermission) newVal).getMask();
if (oldMask != newMask) { if (oldMask != newMask) {
@ -587,7 +582,6 @@ final class KrbServicePermissionCollection extends PermissionCollection
} }
return existingVal; return existingVal;
} }
}
); );
} }