Skip to content

Commit 5d734f7

Browse files
Add nullability check for cache file
1 parent 78e145b commit 5d734f7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/main/java/net/snowflake/client/core/FileCacheManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ synchronized <T> T withLock(Supplier<T> supplier) {
264264
/** Reads the cache file. */
265265
synchronized JsonNode readCacheFile() {
266266
try {
267-
if (!cacheFile.exists()) {
267+
if (cacheFile == null || !cacheFile.exists()) {
268268
logger.debug("Cache file doesn't exists. File: {}", cacheFile);
269269
return null;
270270
}

src/test/java/net/snowflake/client/core/FileCacheManagerTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ public void throwWhenReadCacheFileWithPermissionDifferentThanReadWriteForUserTes
107107
}
108108
}
109109

110+
@Test
111+
@RunOnLinuxOrMac
112+
public void notThrowExceptionWhenCacheFolderIsNotAccessible() throws IOException {
113+
try {
114+
Files.setPosixFilePermissions(
115+
cacheFile.getParentFile().toPath(), PosixFilePermissions.fromString("---------"));
116+
FileCacheManager fcm =
117+
FileCacheManager.builder()
118+
.setCacheDirectorySystemProperty(CACHE_DIR_PROP)
119+
.setCacheDirectoryEnvironmentVariable(CACHE_DIR_ENV)
120+
.setBaseCacheFileName(CACHE_FILE_NAME)
121+
.setCacheFileLockExpirationInSeconds(CACHE_FILE_LOCK_EXPIRATION_IN_SECONDS)
122+
.build();
123+
assertDoesNotThrow(fcm::readCacheFile);
124+
} finally {
125+
Files.setPosixFilePermissions(
126+
cacheFile.getParentFile().toPath(), PosixFilePermissions.fromString("rwx------"));
127+
}
128+
}
129+
110130
@Test
111131
@RunOnLinuxOrMac
112132
public void throwWhenOverrideCacheFileHasDifferentOwnerThanCurrentUserTest() {

0 commit comments

Comments
 (0)