Skip to content

Commit 4444e46

Browse files
cppwfsfmbenhassine
authored andcommitted
Add URL to error message in StaxEventItemReader when resource does not exist
Resolves #1171
1 parent 6880685 commit 4444e46

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
*
6060
* @author Robert Kasanicky
6161
* @author Mahmoud Ben Hassine
62+
* @author Glenn Renfro
6263
*/
6364
public class StaxEventItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
6465
implements ResourceAwareItemReaderItemStream<T>, InitializingBean {
@@ -225,14 +226,16 @@ protected void doOpen() throws Exception {
225226
noInput = true;
226227
if (!resource.exists()) {
227228
if (strict) {
228-
throw new IllegalStateException("Input resource must exist (reader is in 'strict' mode)");
229+
throw new IllegalStateException(
230+
"Input resource " + resource.getURL() + " must exist (reader is in 'strict' mode)");
229231
}
230232
logger.warn("Input resource does not exist " + resource.getDescription());
231233
return;
232234
}
233235
if (!resource.isReadable()) {
234236
if (strict) {
235-
throw new IllegalStateException("Input resource must be readable (reader is in 'strict' mode)");
237+
throw new IllegalStateException(
238+
"Input resource " + resource.getURL() + " must be readable (reader is in 'strict' mode)");
236239
}
237240
logger.warn("Input resource is not readable " + resource.getDescription());
238241
return;

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.io.File;
4848
import java.io.IOException;
4949
import java.io.InputStream;
50+
import java.net.URL;
5051
import java.nio.ByteBuffer;
5152
import java.nio.charset.Charset;
5253
import java.nio.charset.StandardCharsets;
@@ -71,6 +72,7 @@
7172
* @author Robert Kasanicky
7273
* @author Michael Minella
7374
* @author Mahmoud Ben Hassine
75+
* @author Glenn Renfro
7476
*/
7577
class StaxEventItemReaderTests {
7678

@@ -582,7 +584,9 @@ void testStrictness() throws Exception {
582584
source.setStrict(true);
583585
source.afterPropertiesSet();
584586

585-
assertThrows(ItemStreamException.class, () -> source.open(executionContext));
587+
ItemStreamException exception = assertThrows(ItemStreamException.class, () -> source.open(executionContext));
588+
assertEquals("Input resource file:/non/existent/file must exist (reader is in 'strict' mode)",
589+
exception.getCause().getMessage());
586590

587591
}
588592

@@ -834,6 +838,11 @@ public InputStream getInputStream() throws IOException {
834838
return null;
835839
}
836840

841+
@Override
842+
public URL getURL() throws IOException {
843+
return new URL("file:/non/existent/file");
844+
}
845+
837846
}
838847

839848
}

0 commit comments

Comments
 (0)