You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ro...@apache.org on 2022/09/23 17:03:35 UTC
[activemq-artemis] 02/06: remove unused out-of-order exception support to simplify
This is an automated email from the ASF dual-hosted git repository.
robbie pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit 30416716944b94ce84770d046a8c36e5922cc5a9
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Sep 23 16:10:13 2022 +0100
remove unused out-of-order exception support to simplify
---
.../artemis/logs/annotation/LogBundle.java | 2 -
.../processor/LogAnnotationProcessor.java | 11 ++---
.../artemis/logprocessor/SimpleBundle.java | 12 ++---
.../artemis/logprocessor/SimpleBundleTest.java | 52 +++-------------------
4 files changed, 13 insertions(+), 64 deletions(-)
diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
index b57c4b820b..3c6086fffc 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/LogBundle.java
@@ -30,6 +30,4 @@ public @interface LogBundle {
/** if set, every code generated must match this regular expression.
* this is useful to validate ranges.*/
String regexID() default "";
-
- boolean enforceExceptionParameterAsLast() default true;
}
diff --git a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
index 7bed6c9cf1..2d9e0bd666 100644
--- a/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
+++ b/artemis-log-annotation-processor/src/main/java/org/apache/activemq/artemis/logs/annotation/processor/LogAnnotationProcessor.java
@@ -265,9 +265,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
Iterator<? extends VariableElement> parameters = executableMember.getParameters().iterator();
boolean hasParameters = false;
-
VariableElement exceptionParameter = null;
- final boolean enforceLastParam = bundleAnnotation.enforceExceptionParameterAsLast();
// the one that will be used on the call
StringBuffer callList = new StringBuffer();
@@ -275,7 +273,7 @@ public class LogAnnotationProcessor extends AbstractProcessor {
hasParameters = true;
VariableElement parameter = parameters.next();
- boolean isException = verifyIfExceptionArgument(executableMember, parameter, enforceLastParam, parameters.hasNext(), exceptionParameter != null);
+ boolean isException = verifyIfExceptionArgument(executableMember, parameter, parameters.hasNext(), exceptionParameter != null);
if (isException) {
exceptionParameter = parameter;
}
@@ -407,14 +405,13 @@ public class LogAnnotationProcessor extends AbstractProcessor {
VariableElement exceptionParameter = null;
ArrayList<VariableElement> nonExceptionParameters = new ArrayList<>();
- final boolean enforceLastParam = bundleAnnotation.enforceExceptionParameterAsLast();
Iterator<? extends VariableElement> parameters = parametersList.iterator();
while (parameters.hasNext()) {
hasParameters = true;
VariableElement parameter = parameters.next();
- boolean isException = verifyIfExceptionArgument(executableMember, parameter, enforceLastParam, parameters.hasNext(), exceptionParameter != null);
+ boolean isException = verifyIfExceptionArgument(executableMember, parameter, parameters.hasNext(), exceptionParameter != null);
if (isException) {
exceptionParameter = parameter;
} else {
@@ -519,14 +516,14 @@ public class LogAnnotationProcessor extends AbstractProcessor {
}
}
- private static boolean verifyIfExceptionArgument(final ExecutableElement executableMember, final VariableElement parameter, final boolean enforceLastParam, final boolean hasMoreParams, final boolean hasExistingException) {
+ private static boolean verifyIfExceptionArgument(final ExecutableElement executableMember, final VariableElement parameter, final boolean hasMoreParams, final boolean hasExistingException) {
boolean isException = isException(parameter.asType(), parameter);
if (DEBUG) {
debug("Parameter " + parameter + (isException ? "is" : "is not") + " an exception");
}
if (isException) {
- if (enforceLastParam && hasMoreParams) {
+ if (hasMoreParams) {
throw new IllegalArgumentException("Exception argument " + parameter + " has to be the last argument on the list. Look at: " + executableMember);
}
diff --git a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
index 5ae8285dd2..c7636159e7 100644
--- a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
+++ b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundle.java
@@ -26,7 +26,7 @@ import org.apache.activemq.artemis.logs.annotation.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@LogBundle(projectCode = "TST", enforceExceptionParameterAsLast = false)
+@LogBundle(projectCode = "TST")
public interface SimpleBundle {
static SimpleBundle init() {
@@ -77,16 +77,10 @@ public interface SimpleBundle {
@LogMessage(id = 12, value = "This message has the following parameter:: {}", level = LogMessage.Level.WARN)
void myExceptionLogger(String parameter, MyException e);
- @LogMessage(id = 13, value = "This message has the following parameter:: p{}", level = LogMessage.Level.WARN)
- void outOfOrder(MyException e, String parameter);
-
- @LogMessage(id = 14, value = "OutOfOrder with 4 parameters p{} p{} p{}", level = LogMessage.Level.WARN)
- void outOfOrder(MyException p1, String p2, String p3, String p4);
-
- @LogMessage(id = 15, value = "Long with 5 parameters p{} p{} p{} p{} p{}", level = LogMessage.Level.WARN)
+ @LogMessage(id = 13, value = "Long with 5 parameters p{} p{} p{} p{} p{}", level = LogMessage.Level.WARN)
void longParameters(String p1, String p2, String p3, String p4, String p5);
- @LogMessage(id = 16, value = "An Exceptional example", level = LogMessage.Level.WARN)
+ @LogMessage(id = 14, value = "An Exceptional example", level = LogMessage.Level.WARN)
void onlyException(MyException e);
diff --git a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
index b228035360..e9cf827364 100644
--- a/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
+++ b/artemis-log-annotation-processor/src/test/java/org/apache/activemq/artemis/logprocessor/SimpleBundleTest.java
@@ -97,46 +97,6 @@ public class SimpleBundleTest {
SimpleBundle.MESSAGES.myExceptionLogger("hello2", new MyException("this is an exception"));
}
- @Test
- public void outOfOrderException() {
- AssertionLoggerHandler.startCapture(false, true);
- try {
- SimpleBundle.MESSAGES.outOfOrder(createMyException("NotHere"), "2");
- Assert.assertTrue("parameter2 was not on the output", AssertionLoggerHandler.findText("p2"));
- Assert.assertFalse(AssertionLoggerHandler.findText("pNotHere"));
- Assert.assertTrue("Stack trace was not printed", AssertionLoggerHandler.findText("createMyException"));
- Assert.assertFalse("logging not working", AssertionLoggerHandler.findText("{}"));
- } finally {
- AssertionLoggerHandler.stopCapture();
- }
- }
-
- @Test
- public void outOfOrderExceptionLongParameter() {
- try {
- AssertionLoggerHandler.startCapture(false, false);
- SimpleBundle.MESSAGES.outOfOrder(new MyException("ex1"), "2", "3", "4");
- Assert.assertFalse("Exception should not be on the output", AssertionLoggerHandler.findText("pex1"));
- Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p2"));
- Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p3"));
- Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p4"));
- Assert.assertFalse("formatting not working", AssertionLoggerHandler.findText("{}"));
-
- AssertionLoggerHandler.clear();
- AssertionLoggerHandler.startCapture(false, true);
-
- SimpleBundle.MESSAGES.outOfOrder(createMyException("ex1"), "2", "3", "4");
- Assert.assertFalse("Exception should not be on the output", AssertionLoggerHandler.findText("pex1"));
- Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p3"));
- Assert.assertTrue("parameter not found", AssertionLoggerHandler.findText("p4"));
- Assert.assertTrue("stack not found", AssertionLoggerHandler.findText("createMyException"));
- Assert.assertFalse("formatting not working", AssertionLoggerHandler.findText("{}"));
-
- } finally {
- AssertionLoggerHandler.stopCapture();
- }
- }
-
@Test
public void longList() {
AssertionLoggerHandler.startCapture(false, true);
@@ -159,18 +119,18 @@ public class SimpleBundleTest {
try {
AssertionLoggerHandler.startCapture(false, false);
- SimpleBundle.MESSAGES.onlyException(createMyException("MSG7777"));
+ SimpleBundle.MESSAGES.onlyException(createMyExceptionBreadcrumbMethod("MSG7777"));
- Assert.assertTrue(AssertionLoggerHandler.findText("TST16"));
+ Assert.assertTrue(AssertionLoggerHandler.findText("TST14"));
Assert.assertFalse(AssertionLoggerHandler.findText("MSG7777"));
AssertionLoggerHandler.clear();
AssertionLoggerHandler.startCapture(false, true);
- SimpleBundle.MESSAGES.onlyException(createMyException("MSG7777"));
- Assert.assertTrue(AssertionLoggerHandler.findText("TST16"));
+ SimpleBundle.MESSAGES.onlyException(createMyExceptionBreadcrumbMethod("MSG7777"));
+ Assert.assertTrue(AssertionLoggerHandler.findText("TST14"));
Assert.assertTrue(AssertionLoggerHandler.findText("MSG7777"));
- Assert.assertTrue(AssertionLoggerHandler.findText("createMyException"));
+ Assert.assertTrue(AssertionLoggerHandler.findText("createMyExceptionBreadcrumbMethod"));
} finally {
AssertionLoggerHandler.stopCapture();
}
@@ -178,7 +138,7 @@ public class SimpleBundleTest {
// I'm doing it on a method just to assert if this method will appear on the stack trace
- private MyException createMyException(String message) {
+ private MyException createMyExceptionBreadcrumbMethod(String message) {
return new MyException(message);
}