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,25 +1156,19 @@ 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<>() { int oldMask = ((FilePermission)existingVal).getMask();
@Override int newMask = ((FilePermission)newVal).getMask();
public Permission apply(Permission existingVal, if (oldMask != newMask) {
Permission newVal) { int effective = oldMask | newMask;
int oldMask = ((FilePermission)existingVal).getMask(); if (effective == newMask) {
int newMask = ((FilePermission)newVal).getMask(); return newVal;
if (oldMask != newMask) { }
int effective = oldMask | newMask; if (effective != oldMask) {
if (effective == newMask) { return ((FilePermission)newVal).withNewActions(effective);
return newVal;
}
if (effective != oldMask) {
return ((FilePermission)newVal)
.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,27 +1383,20 @@ 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, int oldMask = existingVal.getMask();
new java.util.function.BiFunction<>() { int newMask = newVal.getMask();
@Override if (oldMask != newMask) {
public SocketPermission apply(SocketPermission existingVal, int effective = oldMask | newMask;
SocketPermission newVal) { if (effective == newMask) {
int oldMask = existingVal.getMask(); return newVal;
int newMask = newVal.getMask(); }
if (oldMask != newMask) { if (effective != oldMask) {
int effective = oldMask | newMask; return new SocketPermission(sp.getName(), effective);
if (effective == newMask) {
return newVal;
}
if (effective != oldMask) {
return new SocketPermission(sp.getName(),
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,22 +79,15 @@ 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(), if (oldValue == null) {
new java.util.function.BiFunction<>() { List<UnresolvedPermission> v = new CopyOnWriteArrayList<>();
@Override v.add(unresolvedPermission);
public List<UnresolvedPermission> apply(String key, return v;
List<UnresolvedPermission> oldValue) { } else {
if (oldValue == null) { oldValue.add(unresolvedPermission);
List<UnresolvedPermission> v = return oldValue;
new CopyOnWriteArrayList<>();
v.add(unresolvedPermission);
return v;
} else {
oldValue.add(unresolvedPermission);
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,27 +469,20 @@ 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, int oldMask = existingVal.getMask();
new java.util.function.BiFunction<>() { int newMask = newVal.getMask();
@Override if (oldMask != newMask) {
public PropertyPermission apply(PropertyPermission existingVal, int effective = oldMask | newMask;
PropertyPermission newVal) { if (effective == newMask) {
return newVal;
int oldMask = existingVal.getMask(); }
int newMask = newVal.getMask(); if (effective != oldMask) {
if (oldMask != newMask) { return new PropertyPermission(propName, effective);
int effective = oldMask | newMask;
if (effective == newMask) {
return newVal;
}
if (effective != oldMask) {
return new PropertyPermission(propName, effective);
}
} }
return existingVal;
} }
return existingVal;
} }
); );

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,26 +567,20 @@ 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, int oldMask = ((ServicePermission) existingVal).getMask();
new java.util.function.BiFunction<>() { int newMask = ((ServicePermission) newVal).getMask();
@Override if (oldMask != newMask) {
public Permission apply(Permission existingVal, int effective = oldMask | newMask;
Permission newVal) { if (effective == newMask) {
int oldMask = ((ServicePermission) existingVal).getMask(); return newVal;
int newMask = ((ServicePermission) newVal).getMask(); }
if (oldMask != newMask) { if (effective != oldMask) {
int effective = oldMask | newMask; return new ServicePermission(princName, effective);
if (effective == newMask) {
return newVal;
}
if (effective != oldMask) {
return new ServicePermission(princName, effective);
}
} }
return existingVal;
} }
return existingVal;
} }
); );
} }