19-FixProbableBugs

This commit is contained in:
Adrian-Devries 2025-04-24 12:54:06 +02:00
parent b5bd901b12
commit 64b84508ed
10 changed files with 38 additions and 19 deletions

View file

@ -76,7 +76,7 @@ public class Daemon {
* @param config the configuration to use
*/
public void startServer(final Processor processor, final Configuration... config) {
HttpServer server = null;
HttpServer server;
try {
final ConversionService healthConverter = new ConversionService();
healthConverter.initialize(HealthType.class.getPackage());

View file

@ -39,7 +39,7 @@ class RoutingHandler extends BaseHandler {
} else if (requestMethod.equals("GET")) {
this.guiHandler.handle(exchange);
} else {
error(exchange, 405, String.format("Method % not supported", requestMethod));
error(exchange, 405, String.format("Method %s not supported", requestMethod));
}
}
}

View file

@ -267,13 +267,16 @@ public class ContentRepository {
public Transformation createIdentityTransformation() {
final URL url = ContentRepository.class.getClassLoader().getResource("transform/identity.xsl");
try ( final InputStream input = url.openStream() ) {
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
final XsltExecutable executable = xsltCompiler.compile(new StreamSource(input));
final ResourceType resource = new ResourceType();
resource.setName("identity");
resource.setLocation(url.toString());
return new Transformation(executable, resource);
try {
assert url != null;
try ( final InputStream input = url.openStream() ) {
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
final XsltExecutable executable = xsltCompiler.compile(new StreamSource(input));
final ResourceType resource = new ResourceType();
resource.setName("identity");
resource.setLocation(url.toString());
return new Transformation(executable, resource);
}
} catch (final IOException | SaxonApiException e) {
throw new IllegalStateException("Error creating identity transformation", e);
}

View file

@ -27,6 +27,7 @@ import javax.xml.validation.SchemaFactory;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;
/**
* @author Andreas Penski
@ -43,7 +44,7 @@ public class SchemaProvider {
public static Schema getReportInputSchema() {
if (reportInputSchema == null) {
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
final Source source = resolve(SchemaProvider.class.getResource("/xsd/createReportInput.xsd"));
final Source source = resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/createReportInput.xsd")));
reportInputSchema = createSchema(sf, new Source[] { source }, new ClassPathResourceResolver("/xsd"));
}
return reportInputSchema;
@ -79,7 +80,7 @@ public class SchemaProvider {
*/
public static Schema getScenarioSchema() {
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
return createSchema(sf, resolve(SchemaProvider.class.getResource("/xsd/scenarios.xsd")));
return createSchema(sf, resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/scenarios.xsd"))));
}
}

View file

@ -110,6 +110,7 @@ public class ClassPathResourceResolver implements LSResourceResolver {
: ClassPathResourceResolver.class.getResource(resolved.toASCIIString());
final LSInputImpl input = new LSInputImpl(publicId, systemId, resolved.toASCIIString());
// intentionally not closed, since xml stack wants it open upon return
assert resource != null;
final InputStream in = resource.openStream();
input.setByteStream(in);
return input;

View file

@ -60,6 +60,7 @@ public class CheckAssertionActionTest {
final CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput());
bag.setReport(Helper.load(SAMPLE_REPORT));
assert SAMPLE_ASSERTIONS != null;
final Assertions assertions = Helper.load(SAMPLE_ASSERTIONS, Assertions.class);
final CheckAssertionAction a = new CheckAssertionAction(assertions, TestObjectFactory.createProcessor());
a.check(bag);

View file

@ -61,7 +61,8 @@ public class SchemaBuilderTest {
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().get()).isEqualTo("myname");
assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().orElse(null))
.isEqualTo("myname");
}
@Test

View file

@ -22,6 +22,7 @@ import static org.junit.Assert.assertThrows;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
@ -42,7 +43,7 @@ public class RelativeUriResolverTest {
static {
try {
BASE = RelativeUriResolver.class.getResource("/examples/assertions/").toURI();
BASE = Objects.requireNonNull(RelativeUriResolver.class.getResource("/examples/assertions/")).toURI();
} catch (final URISyntaxException e) {
throw new IllegalStateException(e);
}
@ -68,16 +69,20 @@ public class RelativeUriResolverTest {
@Test
public void testClasspathLocal() throws URISyntaxException, TransformerException {
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("loading").toURI());
this.resolver = new RelativeUriResolver(
Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("loading")).toURI());
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
assert moz != null;
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
assertThat(resolved).isNotNull();
}
@Test
public void testClasspathJAR() throws URISyntaxException, TransformerException {
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("packaged").toURI());
this.resolver = new RelativeUriResolver(
Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("packaged")).toURI());
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("packaged/main.xsd");
assert moz != null;
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
assertThat(resolved).isNotNull();
}

View file

@ -50,25 +50,31 @@ public class VersioningTest {
@Test
public void testBase() throws URISyntaxException {
assert BASE != null;
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThat(result).isNotNull();
}
@Test
public void testFrameworkIncrement() throws URISyntaxException {
assert INCREMENT != null;
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThat(result).isNotNull();
}
@Test
public void testNewFeature() {
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
assertThrows(ConversionService.ConversionException.class, () -> {
assert NEW_FEATURE != null;
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
});
}
@Test
public void testNewVersion() {
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
assertThrows(ConversionService.ConversionException.class, () -> {
assert NEW_VERSION != null;
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
});
}
}

View file

@ -61,6 +61,7 @@ public class SaxonSecurityTest {
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI);
// TODO: Replace call to deprecated method.
compiler.setURIResolver(resolver);
assert resource != null;
final XsltExecutable executable = compiler.compile(new StreamSource(resource.openStream()));
final XsltTransformer transformer = executable.load();
final Source document = InputFactory.read("<root/>".getBytes(), "dummy").getSource();