<commit_before>package fi.evident.apina.java.reader;

import fi.evident.apina.java.model.JavaClass;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public final class ClassReaderUtils {

    private ClassReaderUtils() { }

    public static JavaClass loadClass(Class<?> cl) {
        try (InputStream in = openInputStreamForClassBytes(cl)) {
            return ClassMetadataReader.loadMetadata(in);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static InputStream openInputStreamForClassBytes(Class<?> cl) throws IOException {
        String resourceName = cl.getName().replace('.', '/') + ".class";
        InputStream inputStream = cl.getClassLoader().getResourceAsStream(resourceName);
        if (inputStream != null)
            return inputStream;
        else
            throw new FileNotFoundException(resourceName);
    }
}
<commit_msg>Support loading classes that use system classloader<commit_after>package fi.evident.apina.java.reader;

import fi.evident.apina.java.model.JavaClass;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public final class ClassReaderUtils {

    private ClassReaderUtils() { }

    public static JavaClass loadClass(Class<?> cl) {
        try (InputStream in = openInputStreamForClassBytes(cl)) {
            return ClassMetadataReader.loadMetadata(in);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static InputStream openInputStreamForClassBytes(Class<?> cl) throws IOException {
        String resourceName = cl.getName().replace('.', '/') + ".class";
        ClassLoader classLoader = cl.getClassLoader();
        if (classLoader == null)
            classLoader = ClassLoader.getSystemClassLoader();

        InputStream inputStream = classLoader.getResourceAsStream(resourceName);
        if (inputStream != null)
            return inputStream;
        else
            throw new FileNotFoundException(resourceName);
    }
}

{'fraction_non_alphanumeric': 0.09717568214456677, 'fraction_numerical': 0.0, 'mean_word_length': 3.1633466135458166, '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': '4443857', 'n_tokens_mistral': 533, 'n_tokens_neox': 529, 'n_words': 126}