fixed BUG-43591: jrxml translate build step fails if using jasperreport.dtd
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 26 Mar 2020 12:25:43 +0100
changeset 37241 602682efc345
parent 36943 d602c30bdf92
child 37242 963b1136e42a
fixed BUG 43591: jrxml translate build step fails if using jasperreport.dtd

Translate makes use of a custom EntityResolver to handle jasperreport.dtd
resolving it locally instead of getting it from Internet. This local
resolution is implemented making use of Class.getResourceAsStream
method. The class the method was invoked from was java.lang.System.

Starting from JDK 9, getResourceAsStream invoked in classes within named
Modules looks for the resources only in those modules rather than in the
whole classpath [1]:

> If this class is in a named Module then this method will attempt to find
> the resource in the module. This is done by delegating to the module's class
> loader findResource(String,String) method, invoking it with the module name
> and the absolute name of the resource. Resources in named modules are subject
> to the rules for encapsulation specified in the Module getResourceAsStream
> method and so this method returns null when the resource is a non-".class"
> resource in a package that is not open to the caller's module.
>
> Otherwise, if this class is not in a named module then the rules for searching
> resources associated with a given class are implemented by the defining class
> loader of the class. This method delegates to this object's class loader. If
> this object was loaded by the bootstrap class loader, the method delegates to
> ClassLoader.getSystemResourceAsStream(java.lang.String).

As java.lang.System is in a named Module, dtd's resource was tried to be found within
it and not found.

Fixed by invoking getResourceAsStream on LocalEntityResolver.class which
is not in a named module.

[1] https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getResourceAsStream(java.lang.String)
src-trl/src/org/openbravo/translate/LocalEntityResolver.java
--- a/src-trl/src/org/openbravo/translate/LocalEntityResolver.java	Wed Feb 26 06:14:02 2020 +0000
+++ b/src-trl/src/org/openbravo/translate/LocalEntityResolver.java	Thu Mar 26 12:25:43 2020 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2020 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  _Ville Lindfors_____________________________________.
  ************************************************************************
@@ -34,13 +34,13 @@
 public class LocalEntityResolver implements EntityResolver {
 
   @Override
-  public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
-      IOException {
+  public InputSource resolveEntity(String publicId, String systemId)
+      throws SAXException, IOException {
 
     if (systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd")) {
-      // return a special input source using the system classloader.
-      return new InputSource(
-          System.class.getResourceAsStream("/net/sf/jasperreports/engine/dtds/jasperreport.dtd"));
+      // obtain Jasper dtd from classpath
+      return new InputSource(LocalEntityResolver.class
+          .getResourceAsStream("/net/sf/jasperreports/engine/dtds/jasperreport.dtd"));
     } else {
       // Use default behavior.
       return null;