From 9fee8f8a7eb668909ff919e3ddbd3faf65fe2584 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Fri, 9 Aug 2024 17:16:32 -0400 Subject: [PATCH] fix empty results --- .../service/CompilerService.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/CompilerService.java b/src/main/java/com/primefactorsolutions/service/CompilerService.java index 70b8450..ea657a2 100644 --- a/src/main/java/com/primefactorsolutions/service/CompilerService.java +++ b/src/main/java/com/primefactorsolutions/service/CompilerService.java @@ -47,17 +47,20 @@ public class CompilerService { final Class clazz = classLoader.loadClass(qualifiedClassName); Map results = Map.of(); - Method[] methods = clazz.getMethods(); - for (Method m : methods) { - if ("run".equals(m.getName())) { - try { + try { + Method[] methods = clazz.getMethods(); + for (Method m : methods) { + if ("run".equals(m.getName())) { results = (Map) m.invoke(null, new Object[]{}); - } catch (Exception e) { - results = Map.of("Exception: " + ExceptionUtils.getStackTrace(ExceptionUtils.getRootCause(e)), false); + break; } - - break; } + + if (results.isEmpty()) { + results = Map.of("No existe ningun resultado. Verifique el metodo 'run()'.", false); + } + } catch (Exception e) { + results = Map.of("Exception: " + ExceptionUtils.getStackTrace(ExceptionUtils.getRootCause(e)), false); } return Optional.of(results.entrySet().stream()