Skip to content

Commit

Permalink
Return null from LSResourceResolver.resolveResource() if IOException
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Sep 29, 2023
1 parent f08fbb9 commit 503bf1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 8 additions & 2 deletions sax/src/main/java/org/openjax/xml/sax/XmlCatalogResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) {
}
}

if (entity == null)
return new CachedInputSource(publicId, systemId, baseURI, new URL(systemId).openConnection());
if (entity == null) {
try {
return new CachedInputSource(publicId, systemId, baseURI, new URL(systemId).openConnection());
}
catch (final IOException e) {
return null;
}
}

final CachedInputSource inputSource = entity.getInputSource();
inputSource.getCharacterStream().close();
Expand Down
11 changes: 5 additions & 6 deletions sax/src/test/java/org/openjax/xml/sax/FastSAXParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.junit.Test;
import org.libj.io.ReplayReader;
Expand Down Expand Up @@ -136,7 +135,7 @@ public boolean attribute(final int prefix, final int localName, final int skip,
}
};

private static void add(final List<? super Event> events, final Type type, final String ... fields) {
private static void add(final ArrayList<? super Event> events, final Type type, final String ... fields) {
events.add(new Event(type, fields));
}

Expand All @@ -155,7 +154,7 @@ private static void assertEvent(final Iterator<Event> iterator, final Reader in,
assertEquals(event.fields[i], fields[i]);
}

private static void test(final List<Event> events, final URL url) throws IOException, SAXParseException {
private static void test(final ArrayList<Event> events, final URL url) throws IOException, SAXParseException {
final Iterator<Event> iterator = events.iterator();
try (final Reader in = new ReplayReader(new InputStreamReader(url.openStream()))) {
FastSAXParser.parse(in, new FasterTestHandler(iterator, in));
Expand All @@ -164,7 +163,7 @@ private static void test(final List<Event> events, final URL url) throws IOExcep

@Test
public void testTestXsd() throws IOException, SAXParseException {
final List<Event> events = new ArrayList<>();
final ArrayList<Event> events = new ArrayList<>();
add(events, Type.DOST);
add(events, Type.CMNT, "\n Copyright (c) 2006 OpenJAX\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n You should have received a copy of The MIT License (MIT) along with this\n program. If not, see <http://opensource.org/licenses/MIT/>.\n");
add(events, Type.ELOP, "xs:", "schema");
Expand Down Expand Up @@ -289,7 +288,7 @@ public void testTestXsd() throws IOException, SAXParseException {

@Test
public void testNumeralsXml() throws IOException, SAXParseException {
final List<Event> events = new ArrayList<>();
final ArrayList<Event> events = new ArrayList<>();
add(events, Type.DOST);
add(events, Type.CMNT, "\n Copyright (c) 2008 OpenJAX\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n You should have received a copy of The MIT License (MIT) along with this\n program. If not, see <http://opensource.org/licenses/MIT/>.\n");
add(events, Type.ELOP, "xs:", "schema");
Expand Down Expand Up @@ -333,7 +332,7 @@ public void testNumeralsXml() throws IOException, SAXParseException {

@Test
public void testDoctypeXml() throws IOException, SAXParseException {
final List<Event> events = new ArrayList<>();
final ArrayList<Event> events = new ArrayList<>();
add(events, Type.DOST);
add(events, Type.CMNT, "\n Copyright (c) 2019 OpenJAX\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n You should have received a copy of The MIT License (MIT) along with this\n program. If not, see <http://opensource.org/licenses/MIT/>.\n");
add(events, Type.DOCT, "DOCTYPE catalog [\n <!NOTATION jpeg SYSTEM \"JPG\">\n <!ENTITY prod557 SYSTEM \"prod557.jpg\" NDATA jpeg>\n <!ENTITY prod563 SYSTEM \"prod563.jpg\" NDATA jpeg>\n]");
Expand Down

0 comments on commit 503bf1e

Please sign in to comment.