Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0043532Openbravo ERPA. Platformpublic2020-03-20 13:542020-04-06 15:49
guillermogil 
alostale 
highminoralways
closedfixed 
5
 
3.0PR20Q2 
caristu
Core
No
0043532: jrxml translate build step fails if using jasperreport.dtd
When a jrxml file makes use of jasperreport.dtd, translate build step fails executing with JDK 9+:

Compilation fails in case of an external dtd is used on a JRXML file:
     [java] 1770 [main] ERROR org.openbravo.translate.Translate - file: /XX/XX/XX/XX.jrxml
     [java] java.net.MalformedURLException: null
     [java] at java.net.URL.<init>(URL.java:679) ~[?:?]
     [java] at java.net.URL.<init>(URL.java:541) ~[?:?]
     [java] at java.net.URL.<init>(URL.java:488) ~[?:?]
     [java] at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[xercesImpl.jar:?]
     [java] at org.openbravo.translate.Translate.parseFile(Translate.java:251) [openbravo-trl.jar:?]
     [java] at org.openbravo.translate.Translate$1.visitFile(Translate.java:219) [openbravo-trl.jar:?]
     [java] at org.openbravo.translate.Translate$1.visitFile(Translate.java:208) [openbravo-trl.jar:?]
     [java] at java.nio.file.Files.walkFileTree(Files.java:2724) [?:?]
     [java] at java.nio.file.Files.walkFileTree(Files.java:2796) [?:?]
     [java] at org.openbravo.translate.Translate.execute(Translate.java:208) [openbravo-trl.jar:?]
     [java] at org.openbravo.translate.Translate.main(Translate.java:166) [openbravo-trl.jar:?]
     [java] Caused by: java.lang.NullPointerException
     [java] at java.net.URL.<init>(URL.java:585) ~[?:?]
     [java] ... 19 more
1. Add to C_Order.jrxml the following:
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> [^]
2. Set core module in development
3. run ant smartbuild (sing JDK 11)
No tags attached.
depends on backport 00435913.0PR20Q1.1 closed alostale jrxml translate build step fails if using jasperreport.dtd 
depends on backport 00435923.0PR19Q4.4 closed alostale jrxml translate build step fails if using jasperreport.dtd 
blocks feature request 0037083 closed alostale support JDK 9 
diff 43532.diff (846) 2020-03-25 13:11
https://issues.openbravo.com/file_download.php?file_id=14209&type=bug
Issue History
2020-03-20 13:54guillermogilNew Issue
2020-03-20 13:54guillermogilAssigned To => platform
2020-03-20 13:54guillermogilModules => Core
2020-03-20 13:54guillermogilTriggers an Emergency Pack => No
2020-03-20 13:55alostaleSeveritymajor => minor
2020-03-20 13:55alostaleTypefeature request => defect
2020-03-20 13:55alostaleStatusnew => acknowledged
2020-03-25 12:52shuehnerNote Added: 0118797
2020-03-25 12:59shuehnerNote Added: 0118798
2020-03-25 13:11shuehnerFile Added: 43532.diff
2020-03-25 13:13shuehnerNote Added: 0118799
2020-03-26 12:01alostaleRelationship addedblocks 0037083
2020-03-26 12:06alostaleSummaryCompilation fails in case of an external dtd is used => jrxml translate build step fails if using jasperreport.dtd
2020-03-26 12:06alostaleDescription Updatedbug_revision_view_page.php?rev_id=20630#r20630
2020-03-26 12:06alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=20632#r20632
2020-03-26 12:06alostaleProposed Solution updated
2020-03-26 12:07alostaleDescription Updatedbug_revision_view_page.php?rev_id=20633#r20633
2020-03-26 12:07alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=20634#r20634
2020-03-26 12:07alostaleProposed Solution updated
2020-03-26 12:07alostaleAssigned Toplatform => alostale
2020-03-26 12:48alostaleReview Assigned To => caristu
2020-03-26 13:18alostaleStatusacknowledged => scheduled
2020-03-30 10:18hgbotCheckin
2020-03-30 10:18hgbotNote Added: 0118863
2020-03-30 10:18hgbotCheckin
2020-03-30 10:18hgbotNote Added: 0118864
2020-03-30 10:18hgbotStatusscheduled => resolved
2020-03-30 10:18hgbotResolutionopen => fixed
2020-03-30 10:18hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/0ef412c29220602f3c9286809981bb24d2aa76d9 [^]
2020-04-02 08:47caristuNote Added: 0118911
2020-04-02 08:47caristuStatusresolved => closed
2020-04-02 08:47caristuFixed in Version => 3.0PR20Q2
2020-04-06 11:54hgbotCheckin
2020-04-06 11:54hgbotNote Added: 0118977
2020-04-06 11:54hgbotCheckin
2020-04-06 11:54hgbotNote Added: 0118978
2020-04-06 11:54hgbotStatusclosed => resolved
2020-04-06 11:54hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/devel/pi/rev/0ef412c29220602f3c9286809981bb24d2aa76d9 [^] => http://code.openbravo.com/erp/devel/pi/rev/db6cf35ac8a53ed2514bdf3cec0cee1687ab4cd4 [^]
2020-04-06 15:49cbernerNote Added: 0118992
2020-04-06 15:49cbernerStatusresolved => closed

Notes
(0118797)
shuehner   
2020-03-25 12:52   
Hello,
the proposed solution is most likely wrong.
As it just disables functionality without needing it.

There is already code in place since here:
changeset: 673:d344659ef3bb
date: Thu Apr 17 09:49:26 2008 +0000

Which solved that problem (back then) by having a local copy for this specific dtd avoiding the need for the parser to download it.

But apparently that is now not working correctly in some cases.

So probably we should debug and fix that existing mechanism which should fix the issue without loosing the whole feature of validating the xml against its dtd
(0118798)
shuehner   
2020-03-25 12:59   
Further testing shows this error to only happen if Translate java code is running with openjdk11 and it is NOT failing when running with openjdk8
(0118799)
shuehner   
2020-03-25 13:13   
Talking about attached diff:
Move reading the dtd from jasper jar file to use ClassLoader defined for Translate.java itself. That way it sees the classpath we have defined in our builds.xml on invocation (project.class.path) and properly returns the resources.

Without the change running with Java11 the call returns null when using SystemClassLoader which apparently worked before until java8.
Comparing with the various other getResourceAsStream calls we have in pi they all call it on a concrete class which probably explains why the change in behavior from Java was hidden until now.
(0118863)
hgbot   
2020-03-30 10:18   
Repository: erp/devel/pi
Changeset: 69adcc2cd00b4c9a04ae16b0d49000a0b8e5a4e7
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Mar 26 12:22:20 2020 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/69adcc2cd00b4c9a04ae16b0d49000a0b8e5a4e7 [^]

related to BUG-43532: apply Java formatting

---
M src-trl/src/org/openbravo/translate/LocalEntityResolver.java
---
(0118864)
hgbot   
2020-03-30 10:18   
Repository: erp/devel/pi
Changeset: 0ef412c29220602f3c9286809981bb24d2aa76d9
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Mar 26 12:25:43 2020 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/0ef412c29220602f3c9286809981bb24d2aa76d9 [^]

fixed BUG-43532: 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) [^]

---
M src-trl/src/org/openbravo/translate/LocalEntityResolver.java
---
(0118911)
caristu   
2020-04-02 08:47   
MR: https://gitlab.com/openbravo/product/openbravo/-/merge_requests/53 [^]
(0118977)
hgbot   
2020-04-06 11:54   
Repository: erp/devel/pi
Changeset: 7bfb4609be0de9d08b4ef82936fb2e56cc34a160
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Mar 26 12:22:20 2020 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/7bfb4609be0de9d08b4ef82936fb2e56cc34a160 [^]

related to BUG-43532: apply Java formatting

---
M src-trl/src/org/openbravo/translate/LocalEntityResolver.java
---
(0118978)
hgbot   
2020-04-06 11:54   
Repository: erp/devel/pi
Changeset: db6cf35ac8a53ed2514bdf3cec0cee1687ab4cd4
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Mar 26 12:25:43 2020 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/db6cf35ac8a53ed2514bdf3cec0cee1687ab4cd4 [^]

fixed BUG-43532: 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) [^]

---
M src-trl/src/org/openbravo/translate/LocalEntityResolver.java
---
(0118992)
cberner   
2020-04-06 15:49   
closed: wrongly reopened