From d86647807ebc624529edb1bd07bac3b7ebe9dedf Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 3 Nov 2021 10:54:24 -0400 Subject: [PATCH] Use ReflectionUtils.makeAccessible() - not direct The `LambdaMessageProcessor` and `MethodInvokingMessageSource` call `method.setAccessible(true)` unconditionally. * Use `ReflectionUtils.makeAccessible()` for some optimization * Remove `Content is not allowed in prolog` from the `JaxbMarshallingIntegrationTests` since it is locale dependant and not relevant for the unit test logic --- .../integration/endpoint/MethodInvokingMessageSource.java | 4 ++-- .../integration/handler/LambdaMessageProcessor.java | 2 +- .../jaxbmarshaling/JaxbMarshallingIntegrationTests.java | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java index 28acc65ef9..e535ee92e6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,7 +80,7 @@ public class MethodInvokingMessageSource extends AbstractMessageSource i } Assert.isTrue(!void.class.equals(this.method.getReturnType()), "invalid MessageSource method '" + this.method.getName() + "', a non-void return is required"); - this.method.setAccessible(true); + ReflectionUtils.makeAccessible(this.method); this.initialized = true; } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java index 063f0d2941..2f77fa23cb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/LambdaMessageProcessor.java @@ -84,7 +84,7 @@ public class LambdaMessageProcessor implements MessageProcessor, BeanFac "classes with single method - functional interface implementations."); this.method = methods.iterator().next(); - this.method.setAccessible(true); + ReflectionUtils.makeAccessible(this.method); this.parameterTypes = this.method.getParameterTypes(); this.expectedType = expectedType; } diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java index 1aa527e185..c647297e8b 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,8 +97,7 @@ public class JaxbMarshallingIntegrationTests { Files.write(tempFile, "junk".getBytes()); assertThatExceptionOfType(MessageTransformationException.class) .isThrownBy(() -> this.unmarshallIn.send(new GenericMessage<>(tempFile.toFile()))) - .withCauseInstanceOf(UnmarshallingFailureException.class) - .withStackTraceContaining("Content is not allowed in prolog."); + .withCauseInstanceOf(UnmarshallingFailureException.class); Files.delete(tempFile); }