Skip to content

[JENKINS-75392] Fallback to Default Icon if Specified File is Missing #576

@jenkins-infra-bot

Description

@jenkins-infra-bot

While testing the icon feature in the htmlpublisher-plugin, I noticed that if the user specifies a file that does not exist, the plugin does not fall back to the default icon, attempting instead to load a missing file, resulting in a broken image in the UI.

Steps to reproduce:
1) In the job configuration, set an icon to a file that does not exist
2) Run the job
3) The UI attempts to load a file that is missing, without falling back to the default icon

Proposed fix
A simple fix to this issue can be to edit the getIconFileName() method (in HtmlPublisherTarget.java), adding the check for the file existence:

      public String getIconFileName() {
    String icon;
    if (StringUtils.isNotBlank(actualHtmlPublisherTarget.icon)) {
if (actualHtmlPublisherTarget.icon.startsWith("symbol-")) {
    icon = actualHtmlPublisherTarget.icon;
}
else {
    File iconFile = new File(dir(), actualHtmlPublisherTarget.icon);

    if(iconFile.exists()){
icon = project.getUrl() + dir().getName() + "/" + 
       actualHtmlPublisherTarget.icon;
    }else{
icon = "symbol-document-text"; 
    }
}
    } else {
icon = "symbol-document-text";
    }
    return dir().exists() ? icon : null;
      }

Would this be a useful improvement? If so, I'd be happy to submit a PR!


Originally reported by giovanni_vaccarino, imported from: Fallback to Default Icon if Specified File is Missing
  • status: Open
  • priority: Minor
  • component(s): htmlpublisher-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251211-193728
Raw content of original issue

While testing the icon feature in the htmlpublisher-plugin, I noticed that if the user specifies a file that does not exist, the plugin does not fall back to the default icon, attempting instead to load a missing file, resulting in a broken image in the UI.

Steps to reproduce: 1) In the job configuration, set an icon to a file that does not exist 2) Run the job 3) The UI attempts to load a file that is missing, without falling back to the default icon

Proposed fix A simple fix to this issue can be to edit the getIconFileName() method (in HtmlPublisherTarget.java), adding the check for the file existence:

      public String getIconFileName() {
            String icon;
            if (StringUtils.isNotBlank(actualHtmlPublisherTarget.icon)) {
                if (actualHtmlPublisherTarget.icon.startsWith("symbol-")) {
                    icon = actualHtmlPublisherTarget.icon;
                }
                else {
                    File iconFile = new File(dir(), actualHtmlPublisherTarget.icon);

                    if(iconFile.exists()){
                        icon = project.getUrl() + dir().getName() + "/" + 
       actualHtmlPublisherTarget.icon;
                    }else{
                        icon = "symbol-document-text"; 
                    }
                }
            } else {
                icon = "symbol-document-text";
            }
            return dir().exists() ? icon : null;
      }

Would this be a useful improvement? If so, I'd be happy to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions