Skip to content

Commit

Permalink
Add URL to error message in StaxEventItemReader when resource does no…
Browse files Browse the repository at this point in the history
…t exist

Resolves #1171
  • Loading branch information
cppwfs authored and fmbenhassine committed Sep 15, 2023
1 parent 6880685 commit 4444e46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
*
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
* @author Glenn Renfro
*/
public class StaxEventItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements ResourceAwareItemReaderItemStream<T>, InitializingBean {
Expand Down Expand Up @@ -225,14 +226,16 @@ protected void doOpen() throws Exception {
noInput = true;
if (!resource.exists()) {
if (strict) {
throw new IllegalStateException("Input resource must exist (reader is in 'strict' mode)");
throw new IllegalStateException(
"Input resource " + resource.getURL() + " must exist (reader is in 'strict' mode)");
}
logger.warn("Input resource does not exist " + resource.getDescription());
return;
}
if (!resource.isReadable()) {
if (strict) {
throw new IllegalStateException("Input resource must be readable (reader is in 'strict' mode)");
throw new IllegalStateException(
"Input resource " + resource.getURL() + " must be readable (reader is in 'strict' mode)");
}
logger.warn("Input resource is not readable " + resource.getDescription());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand All @@ -71,6 +72,7 @@
* @author Robert Kasanicky
* @author Michael Minella
* @author Mahmoud Ben Hassine
* @author Glenn Renfro
*/
class StaxEventItemReaderTests {

Expand Down Expand Up @@ -582,7 +584,9 @@ void testStrictness() throws Exception {
source.setStrict(true);
source.afterPropertiesSet();

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

}

Expand Down Expand Up @@ -834,6 +838,11 @@ public InputStream getInputStream() throws IOException {
return null;
}

@Override
public URL getURL() throws IOException {
return new URL("file:/non/existent/file");
}

}

}

0 comments on commit 4444e46

Please sign in to comment.