Migration Deep Dive für 18 · Exception Handling und Logging öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 18 · 100 % Codeabdeckung

Exception Handling und Logging

Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.

3Legacy-Dateien
4Modern-Dateien
61 → 68Codezeilen
8/8vollständig erfasst

Fachliche Einordnung

Legacy

Null/technische Ausnahme und verteiltes Logging

Fehlerkontext ist technisch oder wird durch Rückgabewerte verschleiert.

Modern

Fachliche Exception und strukturierter Service

Eine benannte fachliche Exception trägt den fehlenden Schlüssel und wird zentral geloggt.

Vergleichsfokus: Alle Dateien werden nach technischer Rolle und fachlicher Verantwortung gruppiert.
Wichtige Abgrenzung: One-to-many-Änderungen werden als Gruppe dargestellt; eine künstliche 1:1-Zuordnung wird vermieden.

Vollständige Abdeckungsmatrix

Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.

VergleichsgruppeLegacy-DateienModern-DateienLegacy-ZeilenModern-ZeilenÄhnlichkeit
Build-Konfiguration113434100%
Lookup, Exception und Test23273447%

Gemeinsame Modulstruktur

Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.

Gemeinsam · 19 Zeilenpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>at.aydin.academy</groupId>
        <artifactId>java-modernization-deep-dive</artifactId>
        <version>1.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>18exceptionlogging-pair</artifactId>
    <packaging>pom</packaging>
    <name>Exception Handling und Logging: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

01Build-KonfigurationDirektvergleich · Legacy 34 / Modern 34 Zeilen · Ähnlichkeit 100%

Logging- und Testabhängigkeiten werden verglichen.

Legacy-DateienModern-DateienEinordnung
pom.xmlpom.xmlDirektvergleich
Semantische Ähnlichkeit: 100%

Legacy

Legacy · 34 Zeilenlegacy/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>18exceptionlogging-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>exception-logging-legacy</artifactId>
            <packaging>jar</packaging>
            <name>Exception Logging Legacy</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>

Modern

Modern · 34 Zeilenmodern/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>18exceptionlogging-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>exception-logging-modern</artifactId>
            <packaging>jar</packaging>
            <name>Exception Logging Modern</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>
02Lookup, Exception und TestDirektvergleich · Legacy 27 / Modern 34 Zeilen · Ähnlichkeit 47%

Generische Fehlerbehandlung wird durch domänenspezifische Exception und strukturiertes Logging ersetzt.

Legacy-DateienModern-DateienEinordnung
LegacyCustomerLookup.java
LegacyCustomerLookupTest.java
CustomerLookupService.java
CustomerNotFoundException.java
CustomerLookupServiceTest.java
Direktvergleich
Semantische Ähnlichkeit: 47%

Legacy

package at.aydin.lab.errors.legacy;

// Design Pattern: Exception Shielding (Legacy-Antipattern-Variante) – fängt technische Fehler, verschluckt sie jedoch.
import java.util.*;

public final class LegacyCustomerLookup {
    private final Map<Long, String> data = Map.of(1L, "Aydin");
    public String find(long id) {
        try {
            return data.get(id).toUpperCase();
        } catch (Exception ex) {
            System.err.println(ex);
            return null;
        }
    }
}

Modern

package at.aydin.lab.errors.modern;

import java.util.*;

// Design Pattern: Exception Translator
// Zweck: Technische Abwesenheit wird in eine eindeutige fachliche Exception übersetzt.
public final class CustomerLookupService {
    private static final System.Logger LOG = System.getLogger(CustomerLookupService.class.getName());
    private final Map<Long, String> data = Map.of(1L, "Aydin");
    public String find(long id) {
        return Optional.ofNullable(data.get(id)).map(String::toUpperCase).orElseThrow(() -> {
            LOG.log(System.Logger.Level.WARNING, "customerId={0} not found", id); return new CustomerNotFoundException(id);
            });
    }
}
package at.aydin.lab.errors.modern;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class CustomerLookupServiceTest {
    @Test
    void throwsDomainException() {
        assertEquals("AYDIN", new CustomerLookupService().find(1));
        assertThrows(CustomerNotFoundException.class, () -> new CustomerLookupService().find(99));
    }
}
⌂ Cockpit