OverrideLoader.java

1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright 2026 Egothor
3
// Copyright 2026 Accenture
4
package org.egothor.methodatlas.command;
5
6
import java.io.IOException;
7
import java.nio.file.Path;
8
9
import org.egothor.methodatlas.emit.ClassificationOverride;
10
11
/**
12
 * Loads classification override files into {@link ClassificationOverride}
13
 * instances.
14
 *
15
 * <p>
16
 * Override files carry human-reviewed corrections to AI classification
17
 * results. They are persisted in YAML using the
18
 * {@code ClassificationOverride} schema and re-applied on every subsequent
19
 * MethodAtlas run so that reviewer decisions reproduce deterministically
20
 * across CI builds.
21
 * </p>
22
 *
23
 * <h2>Null handling</h2>
24
 *
25
 * <p>
26
 * Passing {@code null} as the override path is a legitimate signal that the
27
 * caller wants the empty no-op singleton — typical when no
28
 * {@code -override-file} flag was supplied. The loader returns
29
 * {@link ClassificationOverride#empty()} in that case rather than throwing,
30
 * because the absence of an override file is normal, not exceptional.
31
 * </p>
32
 *
33
 * <h2>Thread safety</h2>
34
 *
35
 * <p>
36
 * This class is thread-safe. It carries no instance state and the underlying
37
 * {@link ClassificationOverride#load(Path)} call is itself stateless.
38
 * </p>
39
 *
40
 * @see ClassificationOverride
41
 * @since 1.0.0
42
 */
43
public final class OverrideLoader {
44
45
    /**
46
     * Creates a new override loader. The loader carries no instance state.
47
     */
48
    public OverrideLoader() {
49
        // Intentionally empty; OverrideLoader is stateless.
50
    }
51
52
    /**
53
     * Loads the classification override file at the given path, or returns the
54
     * empty no-op singleton when no override file was configured.
55
     *
56
     * <p>
57
     * The empty singleton is a sentinel: callers can apply it unconditionally
58
     * to every classification without checking for {@code null}, which
59
     * simplifies the orchestration loops in the {@link Command}
60
     * implementations.
61
     * </p>
62
     *
63
     * @param overrideFile path to the YAML override file, or {@code null} when
64
     *                     the caller wants the empty no-op singleton
65
     * @return loaded override set, or the empty singleton; never {@code null}
66
     * @throws IllegalArgumentException if the file exists but cannot be read
67
     *                                  or contains invalid YAML
68
     */
69
    public ClassificationOverride load(Path overrideFile) {
70 2 1. load : removed conditional - replaced equality check with true → KILLED
2. load : removed conditional - replaced equality check with false → KILLED
        if (overrideFile == null) {
71 1 1. load : replaced return value with null for org/egothor/methodatlas/command/OverrideLoader::load → KILLED
            return ClassificationOverride.empty();
72
        }
73
        try {
74 1 1. load : replaced return value with null for org/egothor/methodatlas/command/OverrideLoader::load → KILLED
            return ClassificationOverride.load(overrideFile);
75
        } catch (IOException e) {
76
            throw new IllegalArgumentException("Cannot load override file: " + overrideFile, e);
77
        }
78
    }
79
}

Mutations

70

1.1
Location : load
Killed by : org.egothor.methodatlas.command.OverrideLoaderTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.OverrideLoaderTest]/[method:load_missingFile_throwsIllegalArgumentExceptionNamingPath(java.nio.file.Path)]
removed conditional - replaced equality check with true → KILLED

2.2
Location : load
Killed by : org.egothor.methodatlas.command.OverrideLoaderTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.OverrideLoaderTest]/[method:load_nullPath_returnsEmptySingleton()]
removed conditional - replaced equality check with false → KILLED

71

1.1
Location : load
Killed by : org.egothor.methodatlas.command.OverrideLoaderTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.OverrideLoaderTest]/[method:load_nullPath_returnsEmptySingleton()]
replaced return value with null for org/egothor/methodatlas/command/OverrideLoader::load → KILLED

74

1.1
Location : load
Killed by : org.egothor.methodatlas.command.OverrideLoaderTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.OverrideLoaderTest]/[method:load_validYaml_returnsNonNullOverride(java.nio.file.Path)]
replaced return value with null for org/egothor/methodatlas/command/OverrideLoader::load → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1