From b7e0ddfcccb49945d3aa93ddaa0c0cc78dd1945e Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sat, 22 Jul 2023 22:12:25 -0700 Subject: [PATCH] fix snyk and resolve qodana analysis warnings --- .github/workflows/build.yml | 3 +++ .github/workflows/snyk.yml | 2 +- .../github/benmanes/caffeine/jcache/CacheFactory.java | 7 ++++++- .../jcache/configuration/CaffeineConfiguration.java | 9 +++++---- qodana.yaml | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba115f3144..1cce8ddd72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,10 +8,12 @@ env: ALLOWED_ENDPOINTS: > api.adoptium.net:443 api.github.com:443 + api.snapcraft.io:443 artifactcache.actions.githubusercontent.com:443 caffeine.gradle-enterprise.cloud:443 cdn.azul.com:443 cloudflare.com:443 + docker.io:443 download.java.net:443 downloads.gradle.org:443 downloads.gradle-dn.com:443 @@ -31,6 +33,7 @@ env: repo1.maven.org:443 scans-in.gradle.com:443 services.gradle.org:443 + schemastore.org:443 www.graalvm.org:443 PUBLISH_JDK: 11 EA_JDK: 21 diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml index 695e1678b0..ca6abff5ac 100644 --- a/.github/workflows/snyk.yml +++ b/.github/workflows/snyk.yml @@ -45,7 +45,7 @@ jobs: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} with: command: test - args: --sarif-file-output=snyk.sarif + args: --sarif-file-output=snyk.sarif -- --no-configuration-cache - name: Check file existence id: check_files uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2.0.0 diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java index 5d84b00432..b898dc57e6 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheFactory.java @@ -212,7 +212,12 @@ private CacheProxy newCacheProxy() { /** Creates a cache that reads through on a cache miss. */ private CacheProxy newLoadingCacheProxy() { - CacheLoader cacheLoader = config.getCacheLoaderFactory().create(); + var factory = config.getCacheLoaderFactory(); + if (factory == null) { + throw new IllegalStateException(); + } + + CacheLoader cacheLoader = factory.create(); JCacheLoaderAdapter adapter = new JCacheLoaderAdapter<>( cacheLoader, dispatcher, expiryPolicy, ticker, statistics); CacheProxy cache = new LoadingCacheProxy<>(cacheName, executor, cacheManager, config, diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/CaffeineConfiguration.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/CaffeineConfiguration.java index 8faa03643a..cd1fb235ab 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/CaffeineConfiguration.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/CaffeineConfiguration.java @@ -174,7 +174,7 @@ public CaffeineConfiguration removeCacheEntryListenerConfiguration( } @Override - public Factory> getCacheLoaderFactory() { + public @Nullable Factory> getCacheLoaderFactory() { return delegate.getCacheLoaderFactory(); } @@ -189,15 +189,16 @@ public CaffeineConfiguration setCacheLoaderFactory( } @Override - public Factory> getCacheWriterFactory() { + public @Nullable Factory> getCacheWriterFactory() { return delegate.getCacheWriterFactory(); } /** Returns a writer created by the configured factory or null if not set. */ public @Nullable CacheWriter getCacheWriter() { - if (hasCacheWriter()) { + var factory = delegate.getCacheWriterFactory(); + if (factory != null) { @SuppressWarnings("unchecked") - CacheWriter writer = (CacheWriter) getCacheWriterFactory().create(); + CacheWriter writer = (CacheWriter) factory.create(); return writer; } return null; diff --git a/qodana.yaml b/qodana.yaml index f2b2fae664..6952d25f8c 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -1,11 +1,12 @@ version: "1.0" projectJDK: temurin-11 -linter: jetbrains/qodana-jvm-community:2023.1 +linter: jetbrains/qodana-jvm-community:2023.2 profile: name: qodana.recommended exclude: - name: AutoCloseableResource - name: CastCanBeRemovedNarrowingVariableType + - name: ClassEscapesItsScope - name: CommentedOutCode - name: ConstantValue - name: DanglingJavadoc