Compare commits

...
Author SHA1 Message Date
dholle d6c59f07f6 Add check for duplicate class definition in source files, fixes #422
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 1m52s
SonarQube Scan / SonarQube Trigger (pull_request) Failing after 2m24s
2026-11-10 15:04:47 +01:00
4 changed files with 24 additions and 0 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
public class Bug422 {}
public class Bug422 {}
@@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.Codegen;
import de.dhbwstuttgart.bytecode.FunNGenerator;
import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.environment.DirectoryClassLoader;
import de.dhbwstuttgart.exceptions.CompilerException;
import de.dhbwstuttgart.exceptions.CompilerWarning;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.WarningsException;
@@ -171,6 +172,8 @@ public class JavaTXCompiler {
var numberOfGenerics = decl == null ? 0 : decl.genericTypeVar().size();
var className = pkgName + (!pkgName.isEmpty() ? "." : "") + name;
if (classRegistry.contains(className))
throw new CompilerException("Duplicate class definition: " + className);
classRegistry.addName(className, numberOfGenerics);
input.add(classRegistry.getName(className));
}
@@ -0,0 +1,7 @@
package de.dhbwstuttgart.exceptions;
public class CompilerException extends RuntimeException {
public CompilerException(String message) {
super(message);
}
}
+12
View File
@@ -1,6 +1,8 @@
import de.dhbwstuttgart.bytecode.CodeGenException;
import de.dhbwstuttgart.core.ConsoleInterface;
import de.dhbwstuttgart.exceptions.CompilerException;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.WarningsException;
import de.dhbwstuttgart.util.Logger;
import de.dhbwstuttgart.util.Logger.LogLevel;
@@ -1704,4 +1706,14 @@ public class TestComplete {
var clazz = classFiles.get("Bug406");
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
}
@Test
public void testBug422() throws Exception {
try {
var classFiles = generateClassFiles(createClassLoader(), "Bug422.jav");
fail("Shouldn't compile!");
} catch (CompilerException e) {
assertEquals("Duplicate class definition: Bug422", e.getMessage());
}
}
}