<commit_before>package com.github.invictum.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;

import java.io.File;
import java.util.Collection;

public class ResourceProvider {

    @SuppressWarnings("all")
    private static File getRoot(String rootPath) {
        return new File(Thread.currentThread().getContextClassLoader().getResource(rootPath).getFile());
    }

    public static File getFile(final String root, final String fileName) {
        File rootDirectory = getRoot(root);
        Collection<File> fileList = FileUtils
                .listFiles(rootDirectory, FileFilterUtils.suffixFileFilter(fileName), FileFilterUtils.trueFileFilter());
        if (fileList.size() == 1) {
            return fileList.iterator().next();
        } else {
            String message = String.format("Unable to locate one '%s' file in '%s' directory", fileName, rootDirectory);
            throw new IllegalStateException(message);
        }
    }
}<commit_msg>Fixed issue with NPE of non existing resource loading.  - wrapped NPE in IllegalStateException.<commit_after>package com.github.invictum.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Collection;

public class ResourceProvider {

    private final static Logger LOG = LoggerFactory.getLogger(ResourceProvider.class);

    @SuppressWarnings("all")
    private static File getRoot(String rootPath) {
        try {
            return new File(Thread.currentThread().getContextClassLoader().getResource(rootPath).getFile());
        } catch (RuntimeException e) {
            throw new IllegalStateException(String.format("Failed to detect root at %s", rootPath));
        }
    }

    public static File getFile(final String root, final String fileName) {
        File rootDirectory = getRoot(root);
        Collection<File> fileList = FileUtils
                .listFiles(rootDirectory, FileFilterUtils.suffixFileFilter(fileName), FileFilterUtils.trueFileFilter());
        if (fileList.size() == 1) {
            return fileList.iterator().next();
        } else {
            String message = String.format("Unable to locate one '%s' file in '%s' directory", fileName, rootDirectory);
            throw new IllegalStateException(message);
        }
    }
}
{'fraction_non_alphanumeric': 0.10350515463917526, 'fraction_numerical': 0.0016494845360824743, 'mean_word_length': 3.3949275362318843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6539710', 'n_tokens_mistral': 637, 'n_tokens_neox': 636, 'n_words': 159}