From 9ad5b76542d4c2a03440cbe6ee64e558e6cbb2a0 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Fri, 3 Nov 2023 10:26:43 +0100 Subject: [PATCH] Fix up bad error handling --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 7 +++++-- .../de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 9952a9a8..91e6e673 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -121,7 +121,8 @@ public class JavaTXCompiler { } try { var clazz = classLoader.loadClass(name.toString()); - return ASTFactory.createClass(clazz); + if (clazz != null) + return ASTFactory.createClass(clazz); } catch (ClassNotFoundException ignored) {} return null; } @@ -418,7 +419,9 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - Writer logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream()); + var logFolder = new File(System.getProperty("user.dir") + "/logFiles/"); + if (log) logFolder.mkdirs(); + Writer logFile = log ? new FileWriter(new File(logFolder, "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream()); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index d849cc89..48c4830d 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.syntaxtree.factory; +import java.io.File; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.*; @@ -45,7 +46,7 @@ public class ASTFactory { try { var path = jreClass.getName().replace('.', '/') + ".class"; var classLoader = jreClass.getClassLoader(); - if (classLoader != null) { + if (classLoader != null && new File(path).exists()) { var bytes = IOUtils.toByteArray(Objects.requireNonNull(classLoader.getResourceAsStream(path))); var classReader = new ClassReader(bytes); var classVisitor = new ClassVisitor(Opcodes.ASM7) {