I'm on Mac OSX 10.12.6
This program listens for Tcp requests on the network, reads an XML request and responds with XML.
When I run this program via the command line:
java -classpath target/classes/ com.mycompany.ocip.server.OCIServer
It runs fine and responds to all XML requests.
However, when I run it as a jar file:
java -jar target/ocip-server-jar-with-dependencies.jar
I get an exception:
java.lang.NullPointerException: source at java.util.Objects.requireNonNull(Objects.java:228) at java.util.Scanner.(Scanner.java:578) at com.mycompany.ocip.server.OCIProtocol.readFile(OCIProtocol.java:56) at com.mycompany.ocip.server.OCIProtocol.processInput(OCIProtocol.java:31) at com.mycompany.ocip.server.OCIServer.main(OCIServer.java:85)
When a large response needs to be sent.
The line the exception pertains to is in the code that reads the XML file to be sent in response: (from OCIProtocol.java, in case that's relevant)
public String readFile(String filename) throws IOException {
InputStream inputStream = this.getClass().getResourceAsStream(filename);
Scanner scanner = new Scanner(inputStream, "UTF-8"); // <-- exception
scanner.useDelimiter("\\A");
String text = scanner.hasNext() ? scanner.next() : "";
scanner.close();
return text;
}
The strange thing is this exception:
- only happens when running as a jar file
- only happens when reading a 'large' xml file from the classpath, e.g. 25MB (several smaller files succeed)
I've tried it dozens of times.
The exception doesn't occur when running the program with the classpath set to the target//classes folder
What could cause this behaviour?
EDIT:
As requested: tar output:
Please note that all other XML files get send by the server without issue, except examples/ServiceProviderDnGetSummaryListResponse-Client1.xml
, (maybe relevant: this file is 25MB wheras the others are smaller files)
user$ tar -tf target/ocip-server-jar-with-dependencies.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/mycompany/
com/mycompany/ocip/
com/mycompany/ocip/server/
examples/
META-INF/maven/
META-INF/maven/bw-ocip-server/
META-INF/maven/bw-ocip-server/bw-ocip-server/
META-INF/maven/com.mycompany/
META-INF/maven/com.mycompany/bw-ocip-server/
com/mycompany/ocip/server/OCIProtocol.class
com/mycompany/ocip/server/OCIServer.class
examples/AuthenticationResponse.xml
examples/GroupDnGetActivationListResponse.xml
examples/LoginResponse.xml
examples/LogoutResponse.xml
examples/ServiceProviderCommunicationBarringCriteriaAssignListRequest.xml
examples/ServiceProviderCommunicationBarringCriteriaAssignListResponse.xml
examples/ServiceProviderCommunicationBarringCriteriaGetAssignedListRequest.xml
examples/ServiceProviderCommunicationBarringCriteriaGetAssignedListResponse.xml
examples/ServiceProviderCommunicationBarringProfileGetResponse-NoSMP.xml
examples/ServiceProviderCommunicationBarringProfileGetResponse.xml
examples/ServiceProviderDnGetSummaryListResponse-Client1.xml
examples/ServiceProviderDnGetSummaryListResponse-NoSP.xml
examples/ServiceProviderDnGetSummaryListResponse.xml
examples/ServiceProviderDnGetSummaryListResponse2.xml
examples/ServiceProviderDnGetSummaryListResponse3.xml
examples/ServiceProviderDnGetSummaryListResponse4.xml
examples/ServiceProviderDnGetSummaryListResponse5.xml
examples/ServiceProviderGetListResponse.xml
examples/SystemCommunicationBarringCriteriaGetListRequest.xml
examples/SystemCommunicationBarringCriteriaGetListResponse.xml
examples/UserGetListInGroupResponse.xml
META-INF/maven/bw-ocip-server/bw-ocip-server/pom.properties
META-INF/maven/bw-ocip-server/bw-ocip-server/pom.xml
META-INF/maven/com.mycompany/bw-ocip-server/pom.properties
META-INF/maven/com.mycompany/bw-ocip-server/pom.xml
The call to readFile is as follows:
public String processInput(String theInput) throws IOException {
String theOutput = "";
if (theInput.contains("LoginRequest")) {
theOutput = this.readFile("/examples/LoginResponse.xml");
} else if (theInput.contains("LogoutRequest")) {
theOutput = this.readFile("/examples/LogoutResponse.xml");
} else if (theInput.contains("ServiceProviderDnGetSummaryList")) {
theOutput = this.readFile("/examples/ServiceProviderDNGetSummaryListResponse-Client1.xml");
} else if (theInput.contains("UserGetListInGroupRequest")) {
theOutput = this.readFile("/examples/UserGetListInGroupResponse.xml");
} else if (theInput.contains("ServiceProviderCommunicationBarringProfileGetRequest")) {
theOutput = this.readFile("/examples/ServiceProviderCommunicationBarringProfileGetResponse.xml");
} else if (theInput.contains("ServiceProviderCommunicationBarringCriteriaAssignListRequest")) {
theOutput = this.readFile("/examples/ServiceProviderCommunicationBarringCriteriaAssignListResponse.xml");
} else if (theInput.contains("ServiceProviderCommunicationBarringCriteriaGetAssignedListRequest")) {
theOutput = this.readFile("/examples/ServiceProviderCommunicationBarringCriteriaGetAssignedListResponse.xml");
} else if (theInput.contains("SystemCommunicationBarringCriteriaGetListRequest")) {
theOutput = this.readFile("/examples/SystemCommunicationBarringCriteriaGetListResponse.xml");
} else
theOutput = this.readFile("/examples/AuthenticationResponse.xml");
return theOutput;
}