You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Axel Howind (Jira)" <ji...@apache.org> on 2023/09/04 07:35:00 UTC

[jira] [Closed] (PDFBOX-5671) Non-functional condition in PDFToImage.getImageFormats()

     [ https://issues.apache.org/jira/browse/PDFBOX-5671?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Axel Howind closed PDFBOX-5671.
-------------------------------
    Resolution: Abandoned

While the condition is non-functional, I will provide another issue and patch that also makes this issue obsolete.

> Non-functional condition in PDFToImage.getImageFormats()
> --------------------------------------------------------
>
>                 Key: PDFBOX-5671
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5671
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Axel Howind
>            Priority: Minor
>
> The method returns a comma separated list of supported image formats. It currently contains a non-functional if-condition where the condition always returns true: 
> {code:java}
>     private static String getImageFormats()
>     {
>         StringBuilder retval = new StringBuilder();
>         String[] formats = ImageIO.getWriterFormatNames();
>         for( int i = 0; i < formats.length; i++ )
>         {
>            if (formats[i].equalsIgnoreCase(formats[i]))
>            {
>                retval.append( formats[i] );
>                if( i + 1 < formats.length )
>                {
>                    retval.append( ", " );
>                }
>            }
>         }
>         return retval.toString();
>     }
> {code}
> I believe the purpose of the if-condition has been to filter out duplicates. That has never worked since the method was introduced in 2014 because formats[i] is always compared to itself, which will always return true.
> The if-condition should either be removed, or even better the code simplified to this:
> {code:java}
>     private static String getImageFormats()
>     {
>         return String.join(", ", ImageIO.getWriterFormatNames());
>     }
> {code}
> If filtering duplicates is important, it could be done like this (this implementation does not ignore case however):
> {code:java}
>         return Arrays.stream(ImageIO.getWriterFormatNames())
>                 .sorted()
>                 .distinct()
>                 .collect(Collectors.joining(", "));
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org