Skip to content

Commit 674bdab

Browse files
authored
Feature: JDK 21 (#237)
Migrate project to JDK 21
1 parent b8316e0 commit 674bdab

File tree

10 files changed

+34
-20
lines changed

10 files changed

+34
-20
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
show-progress: false
1515
- uses: actions/setup-java@v4
1616
with:
17-
java-version: 17
17+
java-version: 21
1818
distribution: 'temurin'
1919
cache: 'maven'
2020
- name: Cache SonarCloud packages

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
show-progress: false
2323
- uses: actions/setup-java@v4
2424
with:
25-
java-version: 17
25+
java-version: 21
2626
distribution: 'temurin'
2727
cache: 'maven'
2828
- name: Initialize CodeQL

.github/workflows/dependency-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
runner-os: 'ubuntu-latest'
1616
java-distribution: 'temurin'
17-
java-version: 17
17+
java-version: 21
1818
secrets:
1919
nvd-api-key: ${{ secrets.NVD_API_KEY }}
2020
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/publish-central.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
show-progress: false
1717
- uses: actions/setup-java@v4
1818
with:
19-
java-version: 17
19+
java-version: 21
2020
distribution: 'temurin'
2121
cache: 'maven'
2222
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml

.github/workflows/publish-github.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
show-progress: false
1313
- uses: actions/setup-java@v4
1414
with:
15-
java-version: 17
15+
java-version: 21
1616
distribution: 'temurin'
1717
cache: 'maven'
1818
- name: Enforce project version ${{ github.event.release.tag_name }}

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![Known Vulnerabilities](https://snyk.io/test/github/cryptomator/cryptofs/badge.svg)](https://snyk.io/test/github/cryptomator/cryptofs)
77

88
**CryptoFS:** Implementation of the [Cryptomator](https://github.com/cryptomator/cryptomator) encryption scheme.
9+
For more info about the encryption scheme, read the [docs](https://docs.cryptomator.org/en/latest/security/vault/).
910

1011
## Features
1112

@@ -98,7 +99,7 @@ For more details on how to use the constructed `FileSystem`, you may consult the
9899

99100
### Dependencies
100101

101-
* Java 17
102+
* Java 21
102103
* Maven 3
103104

104105
### Run Maven

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<properties>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<maven.compiler.release>17</maven.compiler.release>
18+
<maven.compiler.release>21</maven.compiler.release>
1919

2020
<!-- dependencies -->
2121
<cryptolib.version>2.2.0</cryptolib.version>
@@ -27,7 +27,7 @@
2727

2828
<!-- test dependencies -->
2929
<junit.jupiter.version>5.10.3</junit.jupiter.version>
30-
<mockito.version>5.2.0</mockito.version>
30+
<mockito.version>5.12.0</mockito.version>
3131
<hamcrest.version>3.0</hamcrest.version>
3232
<jimfs.version>1.3.0</jimfs.version>
3333

@@ -114,7 +114,7 @@
114114
</dependency>
115115
<dependency>
116116
<groupId>org.mockito</groupId>
117-
<artifactId>mockito-inline</artifactId>
117+
<artifactId>mockito-core</artifactId>
118118
<version>${mockito.version}</version>
119119
<scope>test</scope>
120120
</dependency>

src/test/java/org/cryptomator/cryptofs/CryptoFileSystemImplTest.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import static org.hamcrest.Matchers.contains;
7373
import static org.hamcrest.Matchers.containsInAnyOrder;
7474
import static org.mockito.ArgumentMatchers.any;
75-
import static org.mockito.ArgumentMatchers.isA;
7675
import static org.mockito.Mockito.doAnswer;
7776
import static org.mockito.Mockito.doNothing;
7877
import static org.mockito.Mockito.doThrow;
@@ -959,6 +958,7 @@ public void copyDirectory() throws IOException {
959958
when(physicalFsProv.newFileChannel(Mockito.eq(ciphertextDestinationDirFile), Mockito.any(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
960959
when(cryptoPathMapper.getCiphertextFileType(cleartextSource)).thenReturn(CiphertextFileType.DIRECTORY);
961960
when(cryptoPathMapper.getCiphertextFileType(cleartextDestination)).thenThrow(NoSuchFileException.class);
961+
when(physicalFsProv.exists(ciphertextTargetParent)).thenReturn(true);
962962
Mockito.doThrow(new NoSuchFileException("ciphertextDestinationDirFile")).when(physicalFsProv).checkAccess(ciphertextDestinationFile);
963963

964964
inTest.copy(cleartextSource, cleartextDestination);
@@ -1007,6 +1007,7 @@ public void moveDirectoryCopyBasicAttributes() throws IOException {
10071007
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(BasicFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
10081008
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(BasicFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
10091009
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
1010+
when(physicalFsProv.exists(ciphertextTargetParent)).thenReturn(true);
10101011

10111012
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);
10121013

@@ -1027,6 +1028,7 @@ public void moveDirectoryCopyFileOwnerAttributes() throws IOException {
10271028
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextSourceDir), Mockito.same(FileOwnerAttributeView.class), any(LinkOption[].class))).thenReturn(srcAttrsView);
10281029
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(FileOwnerAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
10291030
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
1031+
when(physicalFsProv.exists(ciphertextTargetParent)).thenReturn(true);
10301032

10311033
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);
10321034

@@ -1050,6 +1052,7 @@ public void moveDirectoryCopyPosixAttributes() throws IOException {
10501052
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(PosixFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
10511053
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(PosixFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
10521054
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
1055+
when(physicalFsProv.exists(ciphertextTargetParent)).thenReturn(true);
10531056

10541057
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);
10551058

@@ -1073,6 +1076,7 @@ public void moveDirectoryCopyDosAttributes() throws IOException {
10731076
when(physicalFsProv.readAttributes(Mockito.same(ciphertextSourceDir), Mockito.same(DosFileAttributes.class), any(LinkOption[].class))).thenReturn(srcAttrs);
10741077
when(physicalFsProv.getFileAttributeView(Mockito.same(ciphertextDestinationDir), Mockito.same(DosFileAttributeView.class), any(LinkOption[].class))).thenReturn(dstAttrView);
10751078
when(physicalFsProv.newFileChannel(Mockito.same(ciphertextDestinationDirFile), Mockito.anySet(), any(FileAttribute[].class))).thenReturn(ciphertextTargetDirDirFileFileChannel);
1079+
when(physicalFsProv.exists(ciphertextTargetParent)).thenReturn(true);
10761080

10771081
inTest.copy(cleartextSource, cleartextDestination, StandardCopyOption.COPY_ATTRIBUTES);
10781082

@@ -1168,6 +1172,7 @@ public void createDirectoryIfPathCiphertextFileDoesExistThrowsFileAlreadyExcepti
11681172
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("foo", ciphertextParent));
11691173
when(ciphertextParent.getFileSystem()).thenReturn(fileSystem);
11701174
doThrow(new FileAlreadyExistsException(path.toString())).when(cryptoPathMapper).assertNonExisting(path);
1175+
when(provider.exists(ciphertextParent)).thenReturn(true);
11711176

11721177
FileAlreadyExistsException e = Assertions.assertThrows(FileAlreadyExistsException.class, () -> {
11731178
inTest.createDirectory(path);
@@ -1177,7 +1182,7 @@ public void createDirectoryIfPathCiphertextFileDoesExistThrowsFileAlreadyExcepti
11771182

11781183
@Test
11791184
public void createDirectoryCreatesDirectoryIfConditonsAreMet() throws IOException {
1180-
Path ciphertextParent = mock(Path.class, "ciphertextParent");
1185+
Path ciphertextParent = mock(Path.class, "d/00/00");
11811186
Path ciphertextRawPath = mock(Path.class, "d/00/00/path.c9r");
11821187
Path ciphertextDirFile = mock(Path.class, "d/00/00/path.c9r/dir.c9r");
11831188
Path ciphertextDirPath = mock(Path.class, "d/FF/FF/");
@@ -1187,7 +1192,7 @@ public void createDirectoryCreatesDirectoryIfConditonsAreMet() throws IOExceptio
11871192
when(ciphertextRawPath.resolve("dir.c9r")).thenReturn(ciphertextDirFile);
11881193
when(cryptoPathMapper.getCiphertextFilePath(path)).thenReturn(ciphertextPath);
11891194
when(cryptoPathMapper.getCiphertextDir(path)).thenReturn(new CiphertextDirectory(dirId, ciphertextDirPath));
1190-
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextDirPath));
1195+
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextParent));
11911196
when(cryptoPathMapper.getCiphertextFileType(path)).thenThrow(NoSuchFileException.class);
11921197
when(ciphertextPath.getRawPath()).thenReturn(ciphertextRawPath);
11931198
when(ciphertextPath.getDirFilePath()).thenReturn(ciphertextDirFile);
@@ -1197,6 +1202,7 @@ public void createDirectoryCreatesDirectoryIfConditonsAreMet() throws IOExceptio
11971202
when(ciphertextDirPath.getFileSystem()).thenReturn(fileSystem);
11981203
when(ciphertextDirFile.getName(3)).thenReturn(mock(Path.class, "path.c9r"));
11991204
when(provider.newFileChannel(ciphertextDirFile, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))).thenReturn(channel);
1205+
when(provider.exists(ciphertextParent)).thenReturn(true);
12001206

12011207
inTest.createDirectory(path);
12021208

@@ -1206,7 +1212,7 @@ public void createDirectoryCreatesDirectoryIfConditonsAreMet() throws IOExceptio
12061212

12071213
@Test
12081214
public void createDirectoryClearsDirIdAndDeletesDirFileIfCreatingDirFails() throws IOException {
1209-
Path ciphertextParent = mock(Path.class, "ciphertextParent");
1215+
Path ciphertextParent = mock(Path.class, "d/00/00");
12101216
Path ciphertextRawPath = mock(Path.class, "d/00/00/path.c9r");
12111217
Path ciphertextDirFile = mock(Path.class, "d/00/00/path.c9r/dir.c9r");
12121218
Path ciphertextDirPath = mock(Path.class, "d/FF/FF/");
@@ -1216,7 +1222,7 @@ public void createDirectoryClearsDirIdAndDeletesDirFileIfCreatingDirFails() thro
12161222
when(ciphertextRawPath.resolve("dir.c9r")).thenReturn(ciphertextDirFile);
12171223
when(cryptoPathMapper.getCiphertextFilePath(path)).thenReturn(ciphertextPath);
12181224
when(cryptoPathMapper.getCiphertextDir(path)).thenReturn(new CiphertextDirectory(dirId, ciphertextDirPath));
1219-
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextDirPath));
1225+
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextParent));
12201226
when(cryptoPathMapper.getCiphertextFileType(path)).thenThrow(NoSuchFileException.class);
12211227
when(ciphertextPath.getRawPath()).thenReturn(ciphertextRawPath);
12221228
when(ciphertextPath.getDirFilePath()).thenReturn(ciphertextDirFile);
@@ -1226,15 +1232,18 @@ public void createDirectoryClearsDirIdAndDeletesDirFileIfCreatingDirFails() thro
12261232
when(ciphertextDirPath.getFileSystem()).thenReturn(fileSystem);
12271233
when(ciphertextDirFile.getName(3)).thenReturn(mock(Path.class, "path.c9r"));
12281234
when(provider.newFileChannel(ciphertextDirFile, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))).thenReturn(channel);
1235+
when(provider.exists(ciphertextParent)).thenReturn(true);
12291236

1230-
// make createDirectory with an FileSystemException during Files.createDirectories(ciphertextDirPath)
1231-
doThrow(new IOException()).when(provider).createDirectory(ciphertextDirPath);
1237+
// make createDirectory with an FileSystemException during Files.createDirectories(ciphertextContentDir)
1238+
doThrow(new IOException()).when(provider).readAttributesIfExists(ciphertextDirPath, BasicFileAttributes.class);
1239+
doThrow(new FileAlreadyExistsException("very specific")).when(provider).createDirectory(ciphertextDirPath);
12321240
when(ciphertextDirPath.toAbsolutePath()).thenReturn(ciphertextDirPath);
12331241
when(ciphertextDirPath.getParent()).thenReturn(null);
12341242

1235-
Assertions.assertThrows(IOException.class, () -> {
1243+
var exception = Assertions.assertThrows(FileAlreadyExistsException.class, () -> {
12361244
inTest.createDirectory(path);
12371245
});
1246+
Assertions.assertEquals("very specific", exception.getMessage());
12381247
verify(readonlyFlag).assertWritable();
12391248
verify(provider).delete(ciphertextDirFile);
12401249
verify(dirIdProvider).delete(ciphertextDirFile);
@@ -1243,7 +1252,7 @@ public void createDirectoryClearsDirIdAndDeletesDirFileIfCreatingDirFails() thro
12431252

12441253
@Test
12451254
public void createDirectoryBackupsDirIdInCiphertextDirPath() throws IOException {
1246-
Path ciphertextParent = mock(Path.class, "ciphertextParent");
1255+
Path ciphertextParent = mock(Path.class, "d/00/00");
12471256
Path ciphertextRawPath = mock(Path.class, "d/00/00/path.c9r");
12481257
Path ciphertextDirFile = mock(Path.class, "d/00/00/path.c9r/dir.c9r");
12491258
Path ciphertextDirPath = mock(Path.class, "d/FF/FF/");
@@ -1254,7 +1263,7 @@ public void createDirectoryBackupsDirIdInCiphertextDirPath() throws IOException
12541263
when(ciphertextRawPath.resolve("dir.c9r")).thenReturn(ciphertextDirFile);
12551264
when(cryptoPathMapper.getCiphertextFilePath(path)).thenReturn(ciphertextPath);
12561265
when(cryptoPathMapper.getCiphertextDir(path)).thenReturn(cipherDirObject);
1257-
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextDirPath));
1266+
when(cryptoPathMapper.getCiphertextDir(parent)).thenReturn(new CiphertextDirectory("parentDirId", ciphertextParent));
12581267
when(cryptoPathMapper.getCiphertextFileType(path)).thenThrow(NoSuchFileException.class);
12591268
when(ciphertextPath.getRawPath()).thenReturn(ciphertextRawPath);
12601269
when(ciphertextPath.getDirFilePath()).thenReturn(ciphertextDirFile);
@@ -1264,6 +1273,7 @@ public void createDirectoryBackupsDirIdInCiphertextDirPath() throws IOException
12641273
when(ciphertextDirPath.getFileSystem()).thenReturn(fileSystem);
12651274
when(ciphertextDirFile.getName(3)).thenReturn(mock(Path.class, "path.c9r"));
12661275
when(provider.newFileChannel(ciphertextDirFile, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))).thenReturn(channel);
1276+
when(provider.exists(ciphertextParent)).thenReturn(true);
12671277

12681278
inTest.createDirectory(path);
12691279

src/test/java/org/cryptomator/cryptofs/CryptoPathMapperTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public void testGetCiphertextFileTypeForDirectory() throws IOException {
290290
Mockito.when(underlyingFileSystemProvider.readAttributes(dirFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(Mockito.mock(BasicFileAttributes.class));
291291
Mockito.when(underlyingFileSystemProvider.readAttributes(symlinkFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenThrow(NoSuchFileException.class);
292292
Mockito.when(underlyingFileSystemProvider.readAttributes(contentsFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenThrow(NoSuchFileException.class);
293+
Mockito.when(underlyingFileSystemProvider.exists(dirFilePath, LinkOption.NOFOLLOW_LINKS)).thenReturn(true);
293294

294295
CryptoPathMapper mapper = new CryptoPathMapper(pathToVault, cryptor, dirIdProvider, longFileNameProvider, vaultConfig);
295296

@@ -305,6 +306,7 @@ public void testGetCiphertextFileTypeForSymlink() throws IOException {
305306
Mockito.when(underlyingFileSystemProvider.readAttributes(dirFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenThrow(NoSuchFileException.class);
306307
Mockito.when(underlyingFileSystemProvider.readAttributes(symlinkFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(Mockito.mock(BasicFileAttributes.class));
307308
Mockito.when(underlyingFileSystemProvider.readAttributes(contentsFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenThrow(NoSuchFileException.class);
309+
Mockito.when(underlyingFileSystemProvider.exists(symlinkFilePath, LinkOption.NOFOLLOW_LINKS)).thenReturn(true);
308310

309311
CryptoPathMapper mapper = new CryptoPathMapper(pathToVault, cryptor, dirIdProvider, longFileNameProvider, vaultConfig);
310312

@@ -322,6 +324,7 @@ public void testGetCiphertextFileTypeForShortenedFile() throws IOException {
322324
Mockito.when(underlyingFileSystemProvider.readAttributes(contentsFilePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(Mockito.mock(BasicFileAttributes.class));
323325
Mockito.when(fileNameCryptor.encryptFilename(Mockito.any(), Mockito.eq("LONGCLEAR"), Mockito.any())).thenReturn(Strings.repeat("A", 1000));
324326
Mockito.when(longFileNameProvider.deflate(Mockito.any())).thenReturn(new LongFileNameProvider.DeflatedFileName(c9rPath, null, null));
327+
Mockito.when(underlyingFileSystemProvider.exists(contentsFilePath, LinkOption.NOFOLLOW_LINKS)).thenReturn(true);
325328

326329
CryptoPathMapper mapper = new CryptoPathMapper(pathToVault, cryptor, dirIdProvider, longFileNameProvider, vaultConfig);
327330

0 commit comments

Comments
 (0)