Skip to content

Commit a6c60e5

Browse files
authored
Remove all security manager and java security references (#14801)
* Remove all security manager and java security references, these are noops in JDK24+.
1 parent 36eaacd commit a6c60e5

File tree

17 files changed

+71
-374
lines changed

17 files changed

+71
-374
lines changed

build-tools/build-infra/src/main/groovy/lucene.validation.ecj-lint.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.diffplug.gradle.spotless.SpotlessApply
2+
13
/*
24
* Licensed to the Apache Software Foundation (ASF) under one or more
35
* contributor license agreements. See the NOTICE file distributed with
@@ -74,6 +76,8 @@ def lintTasks = sourceSets.collect { SourceSet sourceSet ->
7476
dependsOn sourceSet.compileClasspath
7577
dependsOn ecjConfiguration
7678

79+
mustRunAfter tasks.withType(SpotlessApply)
80+
7781
// The inputs are all source files from the sourceSet.
7882
inputs.files sourceSet.allSource.asFileTree
7983

build-tools/build-infra/src/main/groovy/lucene.validation.spotless-java.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ configure(allprojects) { prj ->
3232
lineEndings = LineEnding.UNIX
3333
endWithNewline()
3434
googleJavaFormat(deps.versions.googleJavaFormat.get())
35+
removeUnusedImports()
3536

3637
// Apply to all Java sources
3738
target("src/**/*.java")

dev-tools/scripts/addBackcompatIndexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_and_add_index(source: str, indextype: str, index_version: scriptutil.
6060
"dvupdates": "testCreateIndexWithDocValuesUpdates",
6161
"emptyIndex": "testCreateEmptyIndex",
6262
}[indextype]
63-
gradle_args = " ".join(["-Ptests.useSecurityManager=false", "-p lucene/%s" % module, "test", "--tests TestGenerateBwcIndices.%s" % test, "-Dtests.bwcdir=%s" % temp_dir, "-Dtests.codec=default"])
63+
gradle_args = " ".join(["-p lucene/%s" % module, "test", "--tests TestGenerateBwcIndices.%s" % test, "-Dtests.bwcdir=%s" % temp_dir, "-Dtests.codec=default"])
6464
base_dir = os.getcwd()
6565
bc_index_file = os.path.join(temp_dir, filename)
6666

lucene/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Changes in Runtime Behavior
6464
Other
6565
---------------------
6666

67+
* GITHUB#14801: Removed all security manager and java.security-related code, which is effectively dead
68+
in Java 24+. (Dawid Weiss)
69+
6770
* GITHUB#14229: Bump minimum required Java version to 25
6871

6972
* GITHUB#14564: Remove abstractions from MMapDirectory as we need no MR-JAR anymore. (Uwe Schindler)

lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestGenerateBwcIndices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class TestGenerateBwcIndices extends LuceneTestCase {
3939
// To generate backcompat indexes with the current default codec, run the following gradle
4040
// command:
4141
// gradlew test -Ptests.bwcdir=/path/to/store/indexes -Ptests.codec=default
42-
// -Ptests.useSecurityManager=false --tests TestGenerateBwcIndices --max-workers=1
42+
// --tests TestGenerateBwcIndices --max-workers=1
4343
//
4444
// Also add testmethod with one of the index creation methods below, for example:
4545
// -Ptestmethod=testCreateCFS

lucene/core/src/java/org/apache/lucene/util/Constants.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
*/
1717
package org.apache.lucene.util;
1818

19-
import java.security.AccessController;
20-
import java.security.PrivilegedAction;
2119
import java.util.Locale;
2220
import java.util.Optional;
23-
import java.util.logging.Logger;
2421
import org.apache.lucene.store.ReadAdvice;
2522

2623
/** Some useful constants. */
@@ -166,36 +163,10 @@ private static boolean hasFastScalarFMA() {
166163
.orElse(ReadAdvice.RANDOM);
167164

168165
private static String getSysProp(String property) {
169-
try {
170-
return doPrivileged(() -> System.getProperty(property));
171-
} catch (
172-
@SuppressWarnings("unused")
173-
SecurityException se) {
174-
logSecurityWarning(property);
175-
return null;
176-
}
166+
return System.getProperty(property);
177167
}
178168

179169
private static String getSysProp(String property, String def) {
180-
try {
181-
return doPrivileged(() -> System.getProperty(property, def));
182-
} catch (
183-
@SuppressWarnings("unused")
184-
SecurityException se) {
185-
logSecurityWarning(property);
186-
return def;
187-
}
188-
}
189-
190-
private static void logSecurityWarning(String property) {
191-
var log = Logger.getLogger(Constants.class.getName());
192-
log.warning("SecurityManager prevented access to system property: " + property);
193-
}
194-
195-
// Extracted to a method to be able to apply the SuppressForbidden annotation
196-
@SuppressWarnings("removal")
197-
@SuppressForbidden(reason = "security manager")
198-
private static <T> T doPrivileged(PrivilegedAction<T> action) {
199-
return AccessController.doPrivileged(action);
170+
return System.getProperty(property, def);
200171
}
201172
}

lucene/core/src/java/org/apache/lucene/util/NamedThreadFactory.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,8 @@ public NamedThreadFactory(String threadNamePrefix) {
4848
threadPoolNumber.getAndIncrement());
4949
}
5050

51-
@SuppressWarnings("removal")
52-
@SuppressForbidden(reason = "security manager")
5351
private static ThreadGroup getThreadGroup() {
54-
final SecurityManager s = System.getSecurityManager();
55-
if (s != null) {
56-
return s.getThreadGroup();
57-
} else {
58-
return Thread.currentThread().getThreadGroup();
59-
}
52+
return Thread.currentThread().getThreadGroup();
6053
}
6154

6255
private static String checkPrefix(String prefix) {

lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import java.lang.reflect.Array;
2020
import java.lang.reflect.Field;
2121
import java.lang.reflect.Modifier;
22-
import java.security.AccessControlException;
23-
import java.security.AccessController;
24-
import java.security.PrivilegedAction;
2522
import java.text.DecimalFormat;
2623
import java.text.DecimalFormatSymbols;
2724
import java.util.Collection;
@@ -541,15 +538,7 @@ public static long shallowSizeOfInstance(Class<?> clazz) {
541538

542539
// Walk type hierarchy
543540
for (; clazz != null; clazz = clazz.getSuperclass()) {
544-
final Class<?> target = clazz;
545-
final Field[] fields;
546-
try {
547-
fields = doPrivileged((PrivilegedAction<Field[]>) target::getDeclaredFields);
548-
} catch (
549-
@SuppressWarnings("removal")
550-
AccessControlException e) {
551-
throw new RuntimeException("Can't access fields of class: " + target, e);
552-
}
541+
final Field[] fields = clazz.getDeclaredFields();
553542

554543
for (Field f : fields) {
555544
if (!Modifier.isStatic(f.getModifiers())) {
@@ -560,13 +549,6 @@ public static long shallowSizeOfInstance(Class<?> clazz) {
560549
return alignObjectSize(size);
561550
}
562551

563-
// Extracted to a method to give the SuppressForbidden annotation the smallest possible scope
564-
@SuppressWarnings("removal")
565-
@SuppressForbidden(reason = "security manager")
566-
private static <T> T doPrivileged(PrivilegedAction<T> action) {
567-
return AccessController.doPrivileged(action);
568-
}
569-
570552
/** Return shallow size of any <code>array</code>. */
571553
private static long shallowSizeOfArray(Object array) {
572554
long size = NUM_BYTES_ARRAY_HEADER;

lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package org.apache.lucene.util;
1818

1919
import java.lang.reflect.Method;
20-
import java.security.AccessController;
21-
import java.security.PrivilegedAction;
2220
import java.util.Collections;
2321
import java.util.HashSet;
2422
import java.util.Set;
@@ -60,11 +58,6 @@
6058
* VirtualMethod.compareImplementationDistance(this.getClass(), oldMethod, newMethod) &gt; 0);
6159
* </pre>
6260
*
63-
* <p>It is important to use {@link AccessController#doPrivileged(PrivilegedAction)} for the actual
64-
* call to get the implementation distance because the subclass may be in a different package. The
65-
* static constructors do not need to use {@code AccessController} because it just initializes our
66-
* own method reference. The caller should have access to all declared members in its own class.
67-
*
6861
* <p>{@link #getImplementationDistance} returns the distance of the subclass that overrides this
6962
* method. The one with the larger distance should be used preferable. This way also more
7063
* complicated method rename scenarios can be handled (think of 2.9 {@code TokenStream}

lucene/core/src/java24/org/apache/lucene/internal/vectorization/PanamaVectorizationProvider.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818

1919
import java.io.IOException;
2020
import java.lang.foreign.MemorySegment;
21-
import java.security.AccessController;
22-
import java.security.PrivilegedAction;
2321
import java.util.Locale;
2422
import java.util.logging.Logger;
2523
import jdk.incubator.vector.FloatVector;
2624
import org.apache.lucene.codecs.hnsw.FlatVectorsScorer;
2725
import org.apache.lucene.store.IndexInput;
2826
import org.apache.lucene.store.MemorySegmentAccessInput;
2927
import org.apache.lucene.util.Constants;
30-
import org.apache.lucene.util.SuppressForbidden;
3128

3229
/** A vectorization provider that leverages the Panama Vector API. */
3330
final class PanamaVectorizationProvider extends VectorizationProvider {
@@ -36,28 +33,12 @@ final class PanamaVectorizationProvider extends VectorizationProvider {
3633
// would get called before we have a chance to perform sanity checks around the vector API in the
3734
// constructor of this class. Put them in PanamaVectorConstants instead.
3835

39-
// Extracted to a method to be able to apply the SuppressForbidden annotation
40-
@SuppressWarnings("removal")
41-
@SuppressForbidden(reason = "security manager")
42-
private static <T> T doPrivileged(PrivilegedAction<T> action) {
43-
return AccessController.doPrivileged(action);
44-
}
45-
4636
private final VectorUtilSupport vectorUtilSupport;
4737

4838
PanamaVectorizationProvider() {
4939
// hack to work around for JDK-8309727:
50-
try {
51-
doPrivileged(
52-
() ->
53-
FloatVector.fromArray(
54-
FloatVector.SPECIES_PREFERRED,
55-
new float[FloatVector.SPECIES_PREFERRED.length()],
56-
0));
57-
} catch (SecurityException se) {
58-
throw new UnsupportedOperationException(
59-
"We hit initialization failure described in JDK-8309727: " + se);
60-
}
40+
FloatVector.fromArray(
41+
FloatVector.SPECIES_PREFERRED, new float[FloatVector.SPECIES_PREFERRED.length()], 0);
6142

6243
if (PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE < 128) {
6344
throw new UnsupportedOperationException(

0 commit comments

Comments
 (0)