From ca30c5ae4dfcff3c82488ca11f3da01d03a4be03 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Mon, 23 Oct 2023 18:58:21 +0200 Subject: [PATCH 1/8] Do not access factory while instantiating implementation. --- .../ch/cyberduck/core/preferences/UserDefaultsPreferences.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java b/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java index 9abab7cb3b9..6e0ab8dab83 100644 --- a/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java +++ b/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java @@ -55,8 +55,7 @@ public class UserDefaultsPreferences extends DefaultPreferences { private final NSBundle bundle = new BundleApplicationResourcesFinder().bundle(); - private final LRUCache cache = LRUCache.usingLoader(this::loadProperty, - PreferencesFactory.get().getLong("preferences.cache.size")); + private final LRUCache cache = LRUCache.usingLoader(this::loadProperty, 1000); private static final String MISSING_PROPERTY = String.valueOf(StringUtils.INDEX_NOT_FOUND); From b8283badcd08b89815de5f9f611a2b3295980e51 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Mon, 23 Oct 2023 18:59:17 +0200 Subject: [PATCH 2/8] Remove instance variable requiring access to `Local` implementation while loading preferences. --- .../cyberduck/core/preferences/UserDefaultsPreferences.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java b/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java index 6e0ab8dab83..5dd5030f0b4 100644 --- a/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java +++ b/core/dylib/src/main/java/ch/cyberduck/core/preferences/UserDefaultsPreferences.java @@ -53,8 +53,6 @@ public class UserDefaultsPreferences extends DefaultPreferences { private static final Logger log = LogManager.getLogger(UserDefaultsPreferences.class); - private final NSBundle bundle = new BundleApplicationResourcesFinder().bundle(); - private final LRUCache cache = LRUCache.usingLoader(this::loadProperty, 1000); private static final String MISSING_PROPERTY = String.valueOf(StringUtils.INDEX_NOT_FOUND); @@ -72,6 +70,7 @@ public String getDefault(final String property) { // Lookup in the default map final String value = super.getDefault(property); if(null == value) { + final NSBundle bundle = new BundleApplicationResourcesFinder().bundle(); // Missing in default. Lookup in Info.plist NSObject plist = bundle.infoDictionary().objectForKey(property); if(null == plist) { @@ -170,6 +169,7 @@ protected void setDefaults() { this.setDefault("local.user.home", SystemB.INSTANCE.getpwuid(LibC.INSTANCE.getuid()).pw_dir); } + final NSBundle bundle = new BundleApplicationResourcesFinder().bundle(); if(null != bundle) { if(bundle.objectForInfoDictionaryKey("CFBundleName") != null) { this.setDefault("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString()); @@ -272,6 +272,7 @@ public String locale() { @Override public List applicationLocales() { + final NSBundle bundle = new BundleApplicationResourcesFinder().bundle(); return this.toList(bundle.localizations()); } From 8c0ce95ac231ce49ac34017336deae5eac597d66 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Mon, 23 Oct 2023 19:01:18 +0200 Subject: [PATCH 3/8] Access defaults only after calling super. --- .../core/preferences/ApplicationPreferences.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/dylib/src/main/java/ch/cyberduck/core/preferences/ApplicationPreferences.java b/core/dylib/src/main/java/ch/cyberduck/core/preferences/ApplicationPreferences.java index 46d8d4898cc..db577ad9ad6 100644 --- a/core/dylib/src/main/java/ch/cyberduck/core/preferences/ApplicationPreferences.java +++ b/core/dylib/src/main/java/ch/cyberduck/core/preferences/ApplicationPreferences.java @@ -97,9 +97,6 @@ protected void setFactories() { this.setDefault("factory.badgelabeler.class", WorkspaceApplicationBadgeLabeler.class.getName()); this.setDefault("factory.watchservice.class", FSEventWatchService.class.getName()); this.setDefault("factory.editorfactory.class", FSEventWatchEditorFactory.class.getName()); - if(null == this.getDefault("SUExpectsDSASignature")) { - this.setDefault("factory.licensefactory.class", ReceiptFactory.class.getName()); - } this.setDefault("factory.notification.class", NotificationCenter.class.getName()); this.setDefault("factory.iconservice.class", WorkspaceIconService.class.getName()); this.setDefault("factory.filedescriptor.class", LaunchServicesFileDescriptor.class.getName()); @@ -122,4 +119,12 @@ protected void setFactories() { this.setDefault("factory.urlfilewriter.class", WeblocFileWriter.class.getName()); this.setDefault("factory.quicklook.class", QuartzQuickLook.class.getName()); } + + @Override + protected void setDefaults() { + super.setDefaults(); + if(null == this.getDefault("SUExpectsDSASignature")) { + this.setDefault("factory.licensefactory.class", ReceiptFactory.class.getName()); + } + } } From d3dc81aa3a1c5f36ebe4007fabbf8c4ca43a29dd Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 24 Oct 2023 11:10:12 +0200 Subject: [PATCH 4/8] Delete unused property. --- defaults/src/main/resources/default.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/defaults/src/main/resources/default.properties b/defaults/src/main/resources/default.properties index 38772875f4d..9692efc5e28 100644 --- a/defaults/src/main/resources/default.properties +++ b/defaults/src/main/resources/default.properties @@ -73,7 +73,6 @@ profiles.discovery.updater.url=s3://profiles.cyberduck.io browser.cache.size=1000 transfer.cache.size=100 icon.cache.size=200 -preferences.cache.size=1000 fileid.cache.size=10000 # Caching NS* proxy instances. From bcd8e856f42f997200c880458af843c90cfe8bda Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 24 Oct 2023 12:26:00 +0200 Subject: [PATCH 5/8] Logging for no-op usage. --- core/src/main/java/ch/cyberduck/core/Local.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/ch/cyberduck/core/Local.java b/core/src/main/java/ch/cyberduck/core/Local.java index 5b78d78e749..510de4a378d 100644 --- a/core/src/main/java/ch/cyberduck/core/Local.java +++ b/core/src/main/java/ch/cyberduck/core/Local.java @@ -478,6 +478,9 @@ private static FileChannel getWriteChannel(final String path, final boolean appe } public Object lock(final boolean interactive) throws AccessDeniedException { + if(log.isWarnEnabled()) { + log.warn(String.format("No lock support in %s", this)); + } return null; } From b745f347e4782a178513c7e32b52e68b288a90f3 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 24 Oct 2023 15:50:29 +0200 Subject: [PATCH 6/8] Logging. --- core/src/main/java/ch/cyberduck/core/LocalFactory.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/ch/cyberduck/core/LocalFactory.java b/core/src/main/java/ch/cyberduck/core/LocalFactory.java index dc1e7b69640..e4e7abd1c2b 100644 --- a/core/src/main/java/ch/cyberduck/core/LocalFactory.java +++ b/core/src/main/java/ch/cyberduck/core/LocalFactory.java @@ -21,11 +21,14 @@ import ch.cyberduck.core.preferences.PreferencesFactory; import org.apache.commons.lang3.reflect.ConstructorUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public final class LocalFactory extends Factory { + private static final Logger log = LogManager.getLogger(LocalFactory.class); private Constructor constructorCreateFromString; private Constructor constructorCreateFromParentString; @@ -43,6 +46,9 @@ private Local create(final String path) { try { if(null == constructorCreateFromString) { constructorCreateFromString = ConstructorUtils.getMatchingAccessibleConstructor(clazz, String.class); + if(log.isWarnEnabled()) { + log.warn(String.format("Caching constructor %s for class %s", constructorCreateFromString, clazz)); + } } return constructorCreateFromString.newInstance(path); } @@ -55,6 +61,9 @@ private Local create(final Local parent, final String path) { try { if(null == constructorCreateFromParentString) { constructorCreateFromParentString = ConstructorUtils.getMatchingAccessibleConstructor(clazz, parent.getClass(), path.getClass()); + if(log.isWarnEnabled()) { + log.warn(String.format("Caching constructor %s for class %s", constructorCreateFromParentString, clazz)); + } } return constructorCreateFromParentString.newInstance(parent, path); } From f13b113ba33de89389d7778c3a76da19403e5f8f Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 24 Oct 2023 15:52:49 +0200 Subject: [PATCH 7/8] Logging. --- .../main/java/ch/cyberduck/core/LocalFactory.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/main/java/ch/cyberduck/core/LocalFactory.java b/core/src/main/java/ch/cyberduck/core/LocalFactory.java index e4e7abd1c2b..0ce25cb1f3e 100644 --- a/core/src/main/java/ch/cyberduck/core/LocalFactory.java +++ b/core/src/main/java/ch/cyberduck/core/LocalFactory.java @@ -77,6 +77,10 @@ private Local create(final Local parent, final String path) { public static synchronized Local get(final Local parent, final String name) { if(null == singleton) { singleton = new LocalFactory(); + if(log.isDebugEnabled()) { + log.debug(String.format("Using implementation %s", singleton.getClass())); + } + } return singleton.create(parent, name); } @@ -84,6 +88,9 @@ public static synchronized Local get(final Local parent, final String name) { public static synchronized Local get(final String parent, final String name) { if(null == singleton) { singleton = new LocalFactory(); + if(log.isDebugEnabled()) { + log.debug(String.format("Using implementation %s", singleton.getClass())); + } } return singleton.create(singleton.create(parent), name); } @@ -91,6 +98,9 @@ public static synchronized Local get(final String parent, final String name) { public static synchronized Local get(final String path) { if(null == singleton) { singleton = new LocalFactory(); + if(log.isDebugEnabled()) { + log.debug(String.format("Using implementation %s", singleton.getClass())); + } } return singleton.create(path); } @@ -98,6 +108,9 @@ public static synchronized Local get(final String path) { public static synchronized Local get() { if(null == singleton) { singleton = new LocalFactory(); + if(log.isDebugEnabled()) { + log.debug(String.format("Using implementation %s", singleton.getClass())); + } } return singleton.create(); } From db85bd72755600e55bee4a8a9886d51d0a7d7f6d Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 24 Oct 2023 16:06:58 +0200 Subject: [PATCH 8/8] Make sure no default implementation is registered. --- .../main/java/ch/cyberduck/cli/TerminalPreferences.java | 2 ++ .../ch/cyberduck/core/preferences/MemoryPreferences.java | 9 +++++++++ .../java/ch/cyberduck/core/preferences/Preferences.java | 1 - .../cyberduck/core/preferences/PreferencesFactory.java | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/ch/cyberduck/cli/TerminalPreferences.java b/cli/src/main/java/ch/cyberduck/cli/TerminalPreferences.java index c47dcc463eb..8f5db6e96a2 100644 --- a/cli/src/main/java/ch/cyberduck/cli/TerminalPreferences.java +++ b/cli/src/main/java/ch/cyberduck/cli/TerminalPreferences.java @@ -15,6 +15,7 @@ package ch.cyberduck.cli; import ch.cyberduck.core.DisabledConnectionTimeout; +import ch.cyberduck.core.Local; import ch.cyberduck.core.Permission; import ch.cyberduck.core.cryptomator.CryptoVault; import ch.cyberduck.core.cryptomator.random.FastSecureRandomProvider; @@ -46,6 +47,7 @@ public TerminalPreferences(final Preferences persistence) { protected void setFactories() { super.setFactories(); + this.setDefault("factory.local.class", Local.class.getName()); this.setDefault("factory.certificatestore.class", TerminalCertificateStore.class.getName()); this.setDefault("factory.logincallback.class", TerminalLoginCallback.class.getName()); this.setDefault("factory.passwordcallback.class", TerminalPasswordCallback.class.getName()); diff --git a/core/src/main/java/ch/cyberduck/core/preferences/MemoryPreferences.java b/core/src/main/java/ch/cyberduck/core/preferences/MemoryPreferences.java index f292d4373c2..9e37d957b79 100644 --- a/core/src/main/java/ch/cyberduck/core/preferences/MemoryPreferences.java +++ b/core/src/main/java/ch/cyberduck/core/preferences/MemoryPreferences.java @@ -14,6 +14,8 @@ package ch.cyberduck.core.preferences; +import ch.cyberduck.core.Local; + import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -60,4 +62,11 @@ public List applicationLocales() { public List systemLocales() { return Collections.singletonList("en"); } + + @Override + protected void setFactories() { + super.setFactories(); + + this.setDefault("factory.local.class", Local.class.getName()); + } } diff --git a/core/src/main/java/ch/cyberduck/core/preferences/Preferences.java b/core/src/main/java/ch/cyberduck/core/preferences/Preferences.java index 79cc46d1c42..25ae285ccf8 100755 --- a/core/src/main/java/ch/cyberduck/core/preferences/Preferences.java +++ b/core/src/main/java/ch/cyberduck/core/preferences/Preferences.java @@ -499,7 +499,6 @@ protected void setFactories() { this.setDefault("factory.writer.host.class", PlistWriter.class.getName()); this.setDefault("factory.locale.class", DisabledLocale.class.getName()); - this.setDefault("factory.local.class", Local.class.getName()); this.setDefault("factory.certificatestore.class", DisabledCertificateStore.class.getName()); this.setDefault("factory.logincallback.class", DisabledLoginCallback.class.getName()); this.setDefault("factory.passwordcallback.class", DisabledPasswordCallback.class.getName()); diff --git a/core/src/main/java/ch/cyberduck/core/preferences/PreferencesFactory.java b/core/src/main/java/ch/cyberduck/core/preferences/PreferencesFactory.java index 86dc0f50487..b47cfda041a 100644 --- a/core/src/main/java/ch/cyberduck/core/preferences/PreferencesFactory.java +++ b/core/src/main/java/ch/cyberduck/core/preferences/PreferencesFactory.java @@ -24,6 +24,8 @@ import org.apache.logging.log4j.Logger; public final class PreferencesFactory { + private static final Logger log = LogManager.getLogger(PreferencesFactory.class); + private PreferencesFactory() { // } @@ -46,6 +48,7 @@ public static synchronized void set(final Preferences p) { public static synchronized Preferences get() { if(null == preferences) { + log.error("No application preferences registered"); set(new MemoryPreferences()); } return preferences;