Skip to content

Commit 534d333

Browse files
committed
Merge branch 'main' into shared-mini-test-suite
2 parents 0d19981 + d43c411 commit 534d333

File tree

106 files changed

+589
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+589
-530
lines changed

core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import static java.nio.charset.StandardCharsets.UTF_8;
2222

23-
import java.io.File;
2423
import java.io.IOException;
2524
import java.net.URL;
25+
import java.nio.file.Path;
2626
import java.util.ArrayList;
2727
import java.util.Collections;
2828
import java.util.List;
@@ -81,7 +81,7 @@ String process(String value) {
8181
justification = "app is run in same security context as user providing the filename")
8282
@Override
8383
String process(String value) {
84-
try (Scanner scanner = new Scanner(new File(value), UTF_8)) {
84+
try (Scanner scanner = new Scanner(Path.of(value).toFile(), UTF_8)) {
8585
return scanner.nextLine();
8686
} catch (IOException e) {
8787
throw new ParameterException(e);

core/src/main/java/org/apache/accumulo/core/cli/ConfigOpts.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package org.apache.accumulo.core.cli;
2020

21-
import java.io.File;
21+
import java.nio.file.Path;
2222
import java.util.ArrayList;
2323
import java.util.Collections;
2424
import java.util.HashMap;
@@ -70,7 +70,8 @@ public synchronized SiteConfiguration getSiteConfiguration() {
7070
if (siteConfig == null) {
7171
String propsPath = getPropertiesPath();
7272
siteConfig = (propsPath == null ? SiteConfiguration.fromEnv()
73-
: SiteConfiguration.fromFile(new File(propsPath))).withOverrides(getOverrides()).build();
73+
: SiteConfiguration.fromFile(Path.of(propsPath).toFile())).withOverrides(getOverrides())
74+
.build();
7475
}
7576
return siteConfig;
7677
}

core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfoImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import static com.google.common.base.Suppliers.memoize;
2222
import static java.util.Objects.requireNonNull;
2323

24-
import java.io.FileInputStream;
2524
import java.io.IOException;
2625
import java.io.InputStream;
2726
import java.net.URL;
27+
import java.nio.file.Files;
2828
import java.nio.file.Path;
29-
import java.nio.file.Paths;
29+
import java.nio.file.StandardOpenOption;
3030
import java.util.Optional;
3131
import java.util.Properties;
3232
import java.util.function.BiFunction;
@@ -125,14 +125,14 @@ private String getString(ClientProperty property) {
125125
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
126126
justification = "code runs in same security context as user who provided propertiesFilePath")
127127
public static Properties toProperties(String propertiesFilePath) {
128-
return toProperties(Paths.get(propertiesFilePath));
128+
return toProperties(Path.of(propertiesFilePath));
129129
}
130130

131131
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
132132
justification = "code runs in same security context as user who provided propertiesFile")
133133
public static Properties toProperties(Path propertiesFile) {
134134
Properties properties = new Properties();
135-
try (InputStream is = new FileInputStream(propertiesFile.toFile())) {
135+
try (InputStream is = Files.newInputStream(propertiesFile, StandardOpenOption.READ)) {
136136
properties.load(is);
137137
} catch (IOException e) {
138138
throw new IllegalArgumentException("Failed to load properties from " + propertiesFile, e);

core/src/main/java/org/apache/accumulo/core/conf/ClientProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import static com.google.common.base.Preconditions.checkState;
2222

23-
import java.io.File;
2423
import java.io.IOException;
24+
import java.nio.file.Path;
2525
import java.util.Base64;
2626
import java.util.HashMap;
2727
import java.util.Map;
@@ -304,7 +304,7 @@ public static AuthenticationToken getAuthenticationToken(Properties properties)
304304
case "kerberos":
305305
try {
306306
String principal = ClientProperty.AUTH_PRINCIPAL.getValue(properties);
307-
return new KerberosToken(principal, new File(token));
307+
return new KerberosToken(principal, Path.of(token).toFile());
308308
} catch (IOException e) {
309309
throw new IllegalArgumentException(e);
310310
}

core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.net.URI;
2929
import java.net.URISyntaxException;
3030
import java.net.URL;
31+
import java.nio.file.Path;
3132
import java.util.Collections;
3233
import java.util.HashMap;
3334
import java.util.Map;
@@ -93,7 +94,7 @@ public OverridesOption fromEnv() {
9394
if (configFile.startsWith("file://")) {
9495
File f;
9596
try {
96-
f = new File(new URI(configFile));
97+
f = Path.of(new URI(configFile)).toFile();
9798
} catch (URISyntaxException e) {
9899
throw new IllegalArgumentException(
99100
"Failed to load Accumulo configuration from " + configFile, e);

core/src/main/java/org/apache/accumulo/core/conf/cluster/ClusterConfigParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.OutputStream;
2424
import java.io.PrintStream;
2525
import java.nio.file.Files;
26-
import java.nio.file.Paths;
26+
import java.nio.file.Path;
2727
import java.nio.file.StandardOpenOption;
2828
import java.util.HashMap;
2929
import java.util.List;
@@ -80,7 +80,7 @@ public static void validateGroupNames(List<String> names) {
8080
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
8181
public static Map<String,String> parseConfiguration(String configFile) throws IOException {
8282
Map<String,String> results = new HashMap<>();
83-
try (InputStream fis = Files.newInputStream(Paths.get(configFile), StandardOpenOption.READ)) {
83+
try (InputStream fis = Files.newInputStream(Path.of(configFile), StandardOpenOption.READ)) {
8484
Yaml y = new Yaml();
8585
Map<String,Object> config = y.load(fis);
8686
config.forEach((k, v) -> flatten("", k, v, results));
@@ -226,7 +226,7 @@ public static void main(String[] args) throws IOException {
226226
try {
227227
if (args.length == 2) {
228228
// Write to a file instead of System.out if provided as an argument
229-
try (OutputStream os = Files.newOutputStream(Paths.get(args[1]), StandardOpenOption.CREATE);
229+
try (OutputStream os = Files.newOutputStream(Path.of(args[1]));
230230
PrintStream out = new PrintStream(os)) {
231231
outputShellVariables(parseConfiguration(args[0]), new PrintStream(out));
232232
}

core/src/main/java/org/apache/accumulo/core/data/LoadPlan.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.IOException;
2424
import java.lang.reflect.Field;
2525
import java.net.URI;
26-
import java.nio.file.Paths;
2726
import java.util.Arrays;
2827
import java.util.Base64;
2928
import java.util.Collection;
@@ -76,7 +75,7 @@ private static byte[] copy(CharSequence data) {
7675
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
7776
justification = "this code is validating the input")
7877
private static String checkFileName(String fileName) {
79-
Preconditions.checkArgument(Paths.get(fileName).getNameCount() == 1,
78+
Preconditions.checkArgument(java.nio.file.Path.of(fileName).getNameCount() == 1,
8079
"Expected only filename, but got %s", fileName);
8180
return fileName;
8281
}

core/src/main/java/org/apache/accumulo/core/file/rfile/GenerateSplits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import static java.util.stream.Collectors.toCollection;
2323

2424
import java.io.BufferedWriter;
25-
import java.io.FileOutputStream;
2625
import java.io.IOException;
2726
import java.io.OutputStreamWriter;
2827
import java.io.PrintWriter;
28+
import java.nio.file.Files;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
3131
import java.util.Base64;
@@ -196,8 +196,8 @@ public void execute(String[] args) throws Exception {
196196
log.info("Generated {} splits", desiredSplits.size());
197197
if (opts.outputFile != null) {
198198
log.info("Writing splits to file {} ", opts.outputFile);
199-
try (var writer = new PrintWriter(new BufferedWriter(
200-
new OutputStreamWriter(new FileOutputStream(opts.outputFile), UTF_8)))) {
199+
try (var writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
200+
Files.newOutputStream(java.nio.file.Path.of(opts.outputFile)), UTF_8)))) {
201201
desiredSplits.forEach(writer::println);
202202
}
203203
} else {

core/src/main/java/org/apache/accumulo/core/rpc/SslConnectionParams.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.FileNotFoundException;
2323
import java.net.URL;
24+
import java.nio.file.Path;
2425
import java.util.Arrays;
2526

2627
import org.apache.accumulo.core.conf.AccumuloConfiguration;
@@ -140,15 +141,15 @@ public static SslConnectionParams forClient(AccumuloConfiguration configuration)
140141
private static String findKeystore(String keystorePath) throws FileNotFoundException {
141142
try {
142143
// first just try the file
143-
File file = new File(keystorePath);
144+
File file = Path.of(keystorePath).toFile();
144145
if (file.exists()) {
145146
return file.getAbsolutePath();
146147
}
147148
if (!file.isAbsolute()) {
148149
// try classpath
149150
URL url = SslConnectionParams.class.getClassLoader().getResource(keystorePath);
150151
if (url != null) {
151-
file = new File(url.toURI());
152+
file = Path.of(url.toURI()).toFile();
152153
if (file.exists()) {
153154
return file.getAbsolutePath();
154155
}

core/src/main/java/org/apache/accumulo/core/spi/crypto/AESCryptoService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.net.URI;
3232
import java.net.URISyntaxException;
3333
import java.nio.file.Files;
34-
import java.nio.file.Paths;
34+
import java.nio.file.Path;
3535
import java.security.InvalidAlgorithmParameterException;
3636
import java.security.InvalidKeyException;
3737
import java.security.Key;
@@ -607,7 +607,7 @@ public static byte[] wrapKey(Key fek, Key kek) {
607607
public static Key loadKekFromUri(String keyId) {
608608
try {
609609
final java.net.URI uri = new URI(keyId);
610-
return new SecretKeySpec(Files.readAllBytes(Paths.get(uri.getPath())), "AES");
610+
return new SecretKeySpec(Files.readAllBytes(Path.of(uri.getPath())), "AES");
611611
} catch (URISyntaxException | IOException | IllegalArgumentException e) {
612612
throw new CryptoException("Unable to load key encryption key.", e);
613613
}

core/src/test/java/org/apache/accumulo/core/classloader/ContextClassLoaderFactoryTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public class ContextClassLoaderFactoryTest extends WithTestNames {
4747
@BeforeEach
4848
public void setup() throws Exception {
4949

50-
File folder1 = new File(tempFolder, testName() + "_1");
50+
File folder1 = tempFolder.toPath().resolve(testName() + "_1").toFile();
5151
assertTrue(folder1.isDirectory() || folder1.mkdir(), "Failed to make a new sub-directory");
5252
FileUtils.copyURLToFile(
5353
Objects.requireNonNull(this.getClass().getResource("/accumulo.properties")),
54-
new File(folder1, "accumulo.properties"));
55-
uri1 = new File(folder1, "accumulo.properties").toURI().toString();
54+
folder1.toPath().resolve("accumulo.properties").toFile());
55+
uri1 = folder1.toPath().resolve("accumulo.properties").toFile().toURI().toString();
5656

57-
File folder2 = new File(tempFolder, testName() + "_2");
57+
File folder2 = tempFolder.toPath().resolve(testName() + "_2").toFile();
5858
assertTrue(folder2.isDirectory() || folder2.mkdir(), "Failed to make a new sub-directory");
5959
FileUtils.copyURLToFile(
6060
Objects.requireNonNull(this.getClass().getResource("/accumulo2.properties")),
61-
new File(folder2, "accumulo2.properties"));
61+
folder2.toPath().resolve("accumulo2.properties").toFile());
6262
uri2 = folder2.toURI() + ".*";
6363

6464
}

core/src/test/java/org/apache/accumulo/core/cli/PasswordConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
2424
import static org.junit.jupiter.api.Assertions.assertThrows;
2525

26-
import java.io.File;
2726
import java.io.IOException;
2827
import java.io.InputStream;
2928
import java.io.OutputStreamWriter;
3029
import java.io.PipedInputStream;
3130
import java.io.PipedOutputStream;
31+
import java.nio.file.Path;
3232
import java.util.Scanner;
3333

3434
import org.junit.jupiter.api.AfterEach;
@@ -94,7 +94,7 @@ public void testEnv() {
9494
@Test
9595
public void testFile() throws IOException {
9696
argv[1] = "file:pom.xml";
97-
Scanner scan = new Scanner(new File("pom.xml"), UTF_8);
97+
Scanner scan = new Scanner(Path.of("pom.xml").toFile(), UTF_8);
9898
String expected = scan.nextLine();
9999
scan.close();
100100
new JCommander(password).parse(argv);

core/src/test/java/org/apache/accumulo/core/client/ClientPropertiesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
2323

24-
import java.nio.file.Paths;
24+
import java.nio.file.Path;
2525
import java.util.Properties;
2626

2727
import org.apache.accumulo.core.conf.ClientProperty;
@@ -42,7 +42,7 @@ public void testBasic() {
4242
ClientProperty.validate(props1);
4343

4444
Properties props2 =
45-
Accumulo.newClientProperties().from(props1).as("user2", Paths.get("./path2")).build();
45+
Accumulo.newClientProperties().from(props1).as("user2", Path.of("./path2")).build();
4646

4747
// verify props1 is unchanged
4848
assertEquals("inst1", ClientProperty.INSTANCE_NAME.getValue(props1));

core/src/test/java/org/apache/accumulo/core/client/rfile/RFileClientTest.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
public class RFileClientTest {
9191

9292
private String createTmpTestFile() throws IOException {
93-
File dir = new File(System.getProperty("user.dir") + "/target/rfile-test");
93+
File dir = java.nio.file.Path.of(System.getProperty("user.dir")).resolve("target")
94+
.resolve("rfile-test").toFile();
9495
assertTrue(dir.mkdirs() || dir.isDirectory());
9596
File testFile = File.createTempFile("test", ".rf", dir);
9697
assertTrue(testFile.delete() || !testFile.exists());
@@ -242,9 +243,9 @@ public void testFencingScanner() throws Exception {
242243
LocalFileSystem localFs = FileSystem.getLocal(new Configuration());
243244

244245
Range range = new Range(rowStr(3), false, rowStr(14), true);
245-
Scanner scanner =
246-
RFile.newScanner().from(new FencedPath(new Path(new File(testFile).toURI()), range))
247-
.withFileSystem(localFs).build();
246+
Scanner scanner = RFile.newScanner()
247+
.from(new FencedPath(new Path(java.nio.file.Path.of(testFile).toFile().toURI()), range))
248+
.withFileSystem(localFs).build();
248249

249250
TreeMap<Key,Value> expected = new TreeMap<>(testData);
250251

@@ -265,32 +266,27 @@ public void testRequiresRowRange() throws Exception {
265266
// Lastly only the row portion of a key is allowed.
266267

267268
// Test valid Row Ranges
268-
new FencedPath(new Path(new File(testFile).toURI()), new Range());
269+
URI testFileURI = java.nio.file.Path.of(testFile).toFile().toURI();
270+
new FencedPath(new Path(testFileURI), new Range());
269271
// This constructor converts to the proper inclusive/exclusive rows
270-
new FencedPath(new Path(new File(testFile).toURI()),
271-
new Range(rowStr(3), false, rowStr(14), true));
272-
new FencedPath(new Path(new File(testFile).toURI()),
273-
new Range(new Key(rowStr(3)).followingKey(PartialKey.ROW), true,
274-
new Key(rowStr(14)).followingKey(PartialKey.ROW), false));
272+
new FencedPath(new Path(testFileURI), new Range(rowStr(3), false, rowStr(14), true));
273+
new FencedPath(new Path(testFileURI), new Range(new Key(rowStr(3)).followingKey(PartialKey.ROW),
274+
true, new Key(rowStr(14)).followingKey(PartialKey.ROW), false));
275275

276276
// Test invalid Row Ranges
277277
// Missing 0x00 byte
278-
assertThrows(IllegalArgumentException.class,
279-
() -> new FencedPath(new Path(new File(testFile).toURI()),
280-
new Range(new Key(rowStr(3)), true, new Key(rowStr(14)), false)));
278+
assertThrows(IllegalArgumentException.class, () -> new FencedPath(new Path(testFileURI),
279+
new Range(new Key(rowStr(3)), true, new Key(rowStr(14)), false)));
281280
// End key inclusive
282-
assertThrows(IllegalArgumentException.class,
283-
() -> new FencedPath(new Path(new File(testFile).toURI()),
284-
new Range(new Key(rowStr(3)), true, new Key(rowStr(14)), true)));
281+
assertThrows(IllegalArgumentException.class, () -> new FencedPath(new Path(testFileURI),
282+
new Range(new Key(rowStr(3)), true, new Key(rowStr(14)), true)));
285283
// Start key exclusive
286-
assertThrows(IllegalArgumentException.class,
287-
() -> new FencedPath(new Path(new File(testFile).toURI()),
288-
new Range(new Key(rowStr(3)), false, new Key(rowStr(14)), false)));
284+
assertThrows(IllegalArgumentException.class, () -> new FencedPath(new Path(testFileURI),
285+
new Range(new Key(rowStr(3)), false, new Key(rowStr(14)), false)));
289286
// CF is set which is not allowed
290287
assertThrows(IllegalArgumentException.class,
291-
() -> new FencedPath(new Path(new File(testFile).toURI()),
292-
new Range(new Key(rowStr(3), colStr(3)), true,
293-
new Key(rowStr(14)).followingKey(PartialKey.ROW), false)));
288+
() -> new FencedPath(new Path(testFileURI), new Range(new Key(rowStr(3), colStr(3)), true,
289+
new Key(rowStr(14)).followingKey(PartialKey.ROW), false)));
294290
}
295291

296292
@Test
@@ -303,8 +299,8 @@ public void testFencingReader() throws Exception {
303299

304300
Range range = new Range(rowStr(3), false, rowStr(14), true);
305301

306-
RFileSKVIterator reader =
307-
getReader(localFs, UnreferencedTabletFile.ofRanged(localFs, new File(testFile), range));
302+
RFileSKVIterator reader = getReader(localFs,
303+
UnreferencedTabletFile.ofRanged(localFs, java.nio.file.Path.of(testFile).toFile(), range));
308304
reader.seek(new Range(), List.of(), false);
309305

310306
TreeMap<Key,Value> expected = new TreeMap<>(testData);
@@ -331,8 +327,8 @@ public void testWriterTableProperties() throws Exception {
331327
writer.append(testData1.entrySet());
332328
writer.close();
333329

334-
RFileSKVIterator reader =
335-
getReader(localFs, UnreferencedTabletFile.of(localFs, new File(testFile)));
330+
RFileSKVIterator reader = getReader(localFs,
331+
UnreferencedTabletFile.of(localFs, java.nio.file.Path.of(testFile).toFile()));
336332
FileSKVIterator iiter = reader.getIndex();
337333

338334
int count = 0;
@@ -394,8 +390,8 @@ public void testLocalityGroups() throws Exception {
394390

395391
scanner.close();
396392

397-
Reader reader =
398-
(Reader) getReader(localFs, UnreferencedTabletFile.of(localFs, new File(testFile)));
393+
Reader reader = (Reader) getReader(localFs,
394+
UnreferencedTabletFile.of(localFs, java.nio.file.Path.of(testFile).toFile()));
399395
Map<String,ArrayList<ByteSequence>> lGroups = reader.getLocalityGroupCF();
400396
assertTrue(lGroups.containsKey("z"));
401397
assertEquals(2, lGroups.get("z").size());

0 commit comments

Comments
 (0)