This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit 484064c64e0d7283b1e6b95761087c645a00dc90 Author: Gary D. Gregory <[email protected]> AuthorDate: Wed Jul 16 09:29:16 2025 -0400 Improve error handling in org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(String, FTPClientConfig) --- src/changes/changes.xml | 1 + .../commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6ab77216..a6227056 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -92,6 +92,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">NNTPClient.readNewsgroupListing() can use an ArrayList instead of a Vector.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate org.apache.commons.net.util.Charsets.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Performance: NTFTPEntryParser.parseFTPEntry(String) doesn't need to parse timestamps if there is no name.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">Improve error handling in org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(String, FTPClientConfig).</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getChild().</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getNext().</action> diff --git a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java index fc1a5d1c..0261682d 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java @@ -109,7 +109,6 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto // Common method to process both key and config parameters. private FTPFileEntryParser createFileEntryParser(final String key, final FTPClientConfig config) { FTPFileEntryParser parser = null; - // Is the key a possible class name? if (JAVA_QUALIFIED_NAME_PATTERN.matcher(key).matches()) { try { @@ -118,15 +117,14 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto parser = (FTPFileEntryParser) parserClass.getConstructor().newInstance(); } catch (final ClassCastException e) { throw new ParserInitializationException( - parserClass.getName() + " does not implement the interface " + "org.apache.commons.net.ftp.FTPFileEntryParser.", e); - } catch (final Exception | ExceptionInInitializerError e) { + parserClass.getName() + " does not implement the interface " + FTPFileEntryParser.class.getCanonicalName(), e); + } catch (final Exception | LinkageError e) { throw new ParserInitializationException("Error initializing parser", e); } } catch (final ClassNotFoundException e) { // OK, assume it is an alias } } - if (parser == null) { // Now try for aliases final String upperKey = key.toUpperCase(Locale.ENGLISH); if (upperKey.contains(FTPClientConfig.SYST_UNIX_TRIM_LEADING)) { @@ -156,7 +154,6 @@ public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFacto throw new ParserInitializationException("Unknown parser type: " + key); } } - if (parser instanceof Configurable) { ((Configurable) parser).configure(config); }
