<commit_before>package name.abuchen.portfolio.model;

import java.util.HashMap;

import org.eclipse.swt.graphics.Image;

import name.abuchen.portfolio.model.AttributeType.ImageConverter;
import name.abuchen.portfolio.util.ImageUtil;

public final class ImageManager
{
    private HashMap<String, Image> imageCache = new HashMap<String, Image>();
    private static ImageManager instance = new ImageManager();

    public static ImageManager instance()
    {
        return instance;
    }

    private ImageManager()
    {
    }

    public Image getImage(Attributable target, AttributeType attr)
    {
        return getImage(target, attr, 16, 16);
    }

    public Image getImage(Attributable target, AttributeType attr, int width, int height)
    {
        if (target != null && target.getAttributes().exists(attr))
        {
            if (attr.getConverter() instanceof ImageConverter)
            {
                String imgString = target.getAttributes().get(attr).toString();
                String imgKey = imgString + width + height;
                synchronized (imageCache)
                {
                    Image img = imageCache.getOrDefault(imgKey, null);
                    if (img != null)
                        return img;

                    img = ImageUtil.toImage(imgString, width, height);
                    if (img != null)
                    {
                        imageCache.put(imgKey, img);
                        return img;
                    }
                }
            }
        }
        return null;
    }
}<commit_msg>Avoid NPE when image attribute exist but is null<commit_after>package name.abuchen.portfolio.model;

import java.util.HashMap;

import org.eclipse.swt.graphics.Image;

import name.abuchen.portfolio.model.AttributeType.ImageConverter;
import name.abuchen.portfolio.util.ImageUtil;

public final class ImageManager
{
    private HashMap<String, Image> imageCache = new HashMap<String, Image>();
    private static ImageManager instance = new ImageManager();

    public static ImageManager instance()
    {
        return instance;
    }

    private ImageManager()
    {
    }

    public Image getImage(Attributable target, AttributeType attr)
    {
        return getImage(target, attr, 16, 16);
    }

    public Image getImage(Attributable target, AttributeType attr, int width, int height)
    {
        if (target != null && target.getAttributes().exists(attr))
        {
            if (attr.getConverter() instanceof ImageConverter)
            {
                Object imgObject = target.getAttributes().get(attr);
                if (imgObject == null)
                    return null;

                String imgString = String.valueOf(imgObject);
                String imgKey = imgString + width + height;
                synchronized (imageCache)
                {
                    Image img = imageCache.getOrDefault(imgKey, null);
                    if (img != null)
                        return img;

                    img = ImageUtil.toImage(imgString, width, height);
                    if (img != null)
                    {
                        imageCache.put(imgKey, img);
                        return img;
                    }
                }
            }
        }
        return null;
    }
}
{'fraction_non_alphanumeric': 0.08673315200967059, 'fraction_numerical': 0.0024176488365064974, 'mean_word_length': 1.7175697865353037, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3111541', 'n_tokens_mistral': 854, 'n_tokens_neox': 808, 'n_words': 208}