Skip to content

Commit fa85d99

Browse files
committed
Disable ObjectToMapTransformerTests.cycle test
The `ObjectToMapTransformerTests.testObjectToSpelMapTransformerWithCycle()` causes a `StackOverflowError` according to the parent-child-parent cycle in the model under test. This ends up with an error in the Gradle logs: ``` *** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at s\src\java.instrument\share\native\libinstrument\JPLISAgent.c line: 873 ``` * Disable this test to avoid memory overhead and CPU time to let Java determine stack overflow and avoid a build error
1 parent 0e6b70c commit fa85d99

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

spring-integration-core/src/test/java/org/springframework/integration/transformer/ObjectToMapTransformerTests.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.transformer;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2021

2122
import java.io.IOException;
2223
import java.math.BigDecimal;
@@ -28,7 +29,8 @@
2829
import java.util.Map;
2930
import java.util.Objects;
3031

31-
import org.junit.Test;
32+
import org.junit.jupiter.api.Disabled;
33+
import org.junit.jupiter.api.Test;
3234

3335
import org.springframework.context.expression.MapAccessor;
3436
import org.springframework.expression.Expression;
@@ -55,7 +57,7 @@ public class ObjectToMapTransformerTests {
5557

5658
@SuppressWarnings("unchecked")
5759
@Test
58-
public void testObjectToSpelMapTransformer() throws IOException {
60+
public void testObjectToSpelMapTransformer() {
5961
Employee employee = this.buildEmployee();
6062
StandardEvaluationContext context = new StandardEvaluationContext();
6163
context.addPropertyAccessor(new MapAccessor());
@@ -68,9 +70,9 @@ public void testObjectToSpelMapTransformer() throws IOException {
6870
Map<String, Object> transformedMap = (Map<String, Object>) transformedMessage.getPayload();
6971
assertThat(transformedMap).isNotNull();
7072

71-
Object valueFromTheMap = null;
72-
Object valueFromExpression = null;
73-
Expression expression = null;
73+
Object valueFromTheMap;
74+
Object valueFromExpression;
75+
Expression expression;
7476

7577
expression = parser.parseExpression("departments[0]");
7678
valueFromTheMap = transformedMap.get("departments[0]");
@@ -149,7 +151,8 @@ public void testObjectToSpelMapTransformer() throws IOException {
149151
assertThat(valueFromExpression).isEqualTo(valueFromTheMap);
150152
}
151153

152-
@Test(expected = MessageTransformationException.class)
154+
@Disabled("StackOverflowError")
155+
@Test
153156
public void testObjectToSpelMapTransformerWithCycle() {
154157
Employee employee = this.buildEmployee();
155158
Child child = new Child();
@@ -158,11 +161,13 @@ public void testObjectToSpelMapTransformerWithCycle() {
158161
child.setParent(parent);
159162
ObjectToMapTransformer transformer = new ObjectToMapTransformer();
160163
Message<Employee> message = MessageBuilder.withPayload(employee).build();
161-
transformer.transform(message);
164+
assertThatExceptionOfType(MessageTransformationException.class)
165+
.isThrownBy(() -> transformer.transform(message))
166+
.withRootCauseInstanceOf(StackOverflowError.class);
162167
}
163168

164169
@Test
165-
public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField() throws Exception {
170+
public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField() {
166171
Person person = new Person();
167172
person.deathDate = Instant.now();
168173

@@ -172,12 +177,12 @@ public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntry
172177
Map<String, Object> transformedMap = new ObjectToMapTransformer().transformPayload(employee);
173178

174179
// If JSR310 support is enabled by calling findAndRegisterModules() on the Jackson mapper,
175-
// Instant field should not be broken. Thus the count should exactly be 1 here.
180+
// Instant field should not be broken. Therefore, the count should exactly be 1 here.
176181
assertThat(transformedMap.values().stream().filter(Objects::nonNull).count()).isEqualTo(1L);
177182
}
178183

179184
@Test
180-
public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString() throws Exception {
185+
public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString() {
181186
Employee employee = buildEmployee();
182187

183188
ObjectMapper customMapper = new ObjectMapper();
@@ -203,20 +208,20 @@ public Employee buildEmployee() {
203208
companyAddress.setStreet("1123 Main");
204209
companyAddress.setZip("12345");
205210

206-
Map<String, Long[]> coordinates = new HashMap<String, Long[]>();
207-
coordinates.put("latitude", new Long[] { (long) 1, (long) 5, (long) 13 });
208-
coordinates.put("longitude", new Long[] { (long) 156 });
211+
Map<String, Long[]> coordinates = new HashMap<>();
212+
coordinates.put("latitude", new Long[]{ (long) 1, (long) 5, (long) 13 });
213+
coordinates.put("longitude", new Long[]{ (long) 156 });
209214
companyAddress.setCoordinates(coordinates);
210215

211-
List<Date> datesA = new ArrayList<Date>();
216+
List<Date> datesA = new ArrayList<>();
212217
datesA.add(new Date(System.currentTimeMillis() + 10000));
213218
datesA.add(new Date(System.currentTimeMillis() + 20000));
214219

215-
List<Date> datesB = new ArrayList<Date>();
220+
List<Date> datesB = new ArrayList<>();
216221
datesB.add(new Date(System.currentTimeMillis() + 30000));
217222
datesB.add(new Date(System.currentTimeMillis() + 40000));
218223

219-
List<List<Date>> listOfDates = new ArrayList<List<Date>>();
224+
List<List<Date>> listOfDates = new ArrayList<>();
220225
listOfDates.add(datesA);
221226
listOfDates.add(datesB);
222227

@@ -238,31 +243,31 @@ public Employee buildEmployee() {
238243
Address personAddress = new Address();
239244
personAddress.setCity("Philly");
240245
personAddress.setStreet("123 Main");
241-
List<String> listTestData = new ArrayList<String>();
246+
List<String> listTestData = new ArrayList<>();
242247
listTestData.add("hello");
243248
listTestData.add("blah");
244-
Map<String, List<String>> mapWithListTestData = new HashMap<String, List<String>>();
249+
Map<String, List<String>> mapWithListTestData = new HashMap<>();
245250
mapWithListTestData.put("mapWithListTestData", listTestData);
246251
personAddress.setMapWithListData(mapWithListTestData);
247252
person.setAddress(personAddress);
248253

249-
Map<String, Object> remarksA = new HashMap<String, Object>();
250-
Map<String, Object> remarksB = new HashMap<String, Object>();
254+
Map<String, Object> remarksA = new HashMap<>();
255+
Map<String, Object> remarksB = new HashMap<>();
251256
remarksA.put("foo", "foo");
252257
remarksA.put("bar", "bar");
253258
remarksB.put("baz", "baz");
254-
List<Map<String, Object>> remarks = new ArrayList<Map<String, Object>>();
259+
List<Map<String, Object>> remarks = new ArrayList<>();
255260
remarks.add(remarksA);
256261
remarks.add(remarksB);
257262
person.setRemarks(remarks);
258263
employee.setPerson(person);
259264

260-
Map<String, Map<String, Object>> testMapData = new HashMap<String, Map<String, Object>>();
265+
Map<String, Map<String, Object>> testMapData = new HashMap<>();
261266

262-
Map<String, Object> internalMapA = new HashMap<String, Object>();
267+
Map<String, Object> internalMapA = new HashMap<>();
263268
internalMapA.put("foo", "foo");
264269
internalMapA.put("bar", "bar");
265-
Map<String, Object> internalMapB = new HashMap<String, Object>();
270+
Map<String, Object> internalMapB = new HashMap<>();
266271
internalMapB.put("baz", "baz");
267272

268273
testMapData.put("internalMapA", internalMapA);

0 commit comments

Comments
 (0)