eclipse-birt / birt

Eclipse BIRT™ The open source reporting and data visualization project.
http://www.eclipse.org/birt
Eclipse Public License 2.0
458 stars 393 forks source link

Very misleading exception stacktrace when an image file is not found at runtime #1597

Closed hvbtup closed 7 months ago

hvbtup commented 8 months ago

Situation: Using the BIRT runtime on a Linux system (with case-sensitive filenames). The report contains an image where the image filename is read from the database. The report expects the image as eg. "../logos/logo_na.jpg", but there is only a file called "../logos/logo_NA.jpg".

Note that the URL does not contain a "file:" protocol.

grafik

Note: The filename expression is more complicated in reality (as seen in the screenshot), but "../logos/logo_na.jpg" is the exppression result.

An error message that I would prefer to see in the log would be something like "Image file ../logos/logo_na.jpg not found".

Instead, at runtime I get the following stack trace:

BIRT runAndRenderTask error org.eclipse.birt.report.engine.api.EngineException: Error happened while running the report. at org.eclipse.birt.report.engine.api.impl.EngineTask.handleFatalExceptions(EngineTask.java:1867) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:153) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:69) at com.tp.server.lisa.birt.report.BirtReportGenerator.run(BirtReportGenerator.java:444) Caused by: java.lang.IllegalArgumentException at java.base/sun.net.www.ParseUtil.decode(ParseUtil.java:204) at java.base/sun.net.www.protocol.file.Handler.openConnection(Handler.java:80) at java.base/sun.net.www.protocol.file.Handler.openConnection(Handler.java:72) at java.base/java.net.URL.openConnection(URL.java:1094) at java.base/java.net.URL.openStream(URL.java:1161) at org.eclipse.birt.report.model.util.ResourceLocatorImplBase.tryURLSearch(ResourceLocatorImplBase.java:260) at org.eclipse.birt.report.model.util.ResourceLocatorImplBase.tryURLSearch(ResourceLocatorImplBase.java:236) at org.eclipse.birt.report.model.util.ResourceLocatorImplBase.getResource(ResourceLocatorImplBase.java:188) at org.eclipse.birt.report.model.util.ResourceLocatorImplBase.findResource(ResourceLocatorImplBase.java:80) at org.eclipse.birt.report.model.core.ModuleImpl.findResource(ModuleImpl.java:1214) at org.eclipse.birt.report.model.api.ModuleHandleImpl.findResource(ModuleHandleImpl.java:2056) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.localizeImage(LocalizedContentVisitor.java:608) at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.localize(LocalizedContentVisitor.java:169) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:36) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:62) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:97) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:136) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:66) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLRepeatHeaderLM.layoutChildren(HTMLRepeatHeaderLM.java:54) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:66) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:66) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLRepeatHeaderLM.layoutChildren(HTMLRepeatHeaderLM.java:54) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:66) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27) at org.eclipse.birt.report.engine.layout.html.HTMLListLM.layoutChildren(HTMLListLM.java:68) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:66) at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92) at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:97) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:145) ... 2 more

By looking at the stacktrace, I could only guess that the error is related to an image in the report (from the line containing localizeImage). But why should there be an java.lang.IllegalArgumentException in parsing the URL?

I could not find current source code for the sun.net.www.ParseUtil class. I only found an older version, and there it seems like this IllegalArgumentException without detailed information is caused by an invalid % escape sequence.

But our file name does not contain any percent symbols, so what happens here?

Note: The report is running on a Czech computer at the customer's site; maybe some at some place an error message with non-ASCII characters is treated as a URL? I cannot debug it there, and I'm not able to reproduce it in the IDE.

speckyspooky commented 8 months ago

The IllegalArgumentException will occure if there would be an invalid (URL-)encrypted character included at the URL-path and it tries to convert/decode it back. So if the encrypted path woul include an unencrypted "space" then you would get the error trace. Or there is a invisible control character given or special CZ-characters with the same problem. Based on this trace the runtime crashed before the file was searched finally.

hvbtup commented 8 months ago

Based on this trace the runtime crashed before the file was searched finally.

I don't think so. The file was searched first in findResource (IIRC), but it was not found due to the wrong case in the file name. This is so far expected behavior. Then BIRT tries to interprete the filename as a URL. But the file name is containing just ASCII characters, without spaces.

The IllegalArgumentException will occure if there would be an invalid (URL-)encrypted character included at the URL-path and it tries to convert/decode it back.

Yes, that's what I think too from looking at the code of ParseUtil.decode.

What I don't understand, however, is why this can happen if the file name looks as innocent as "../logos/logo_NA.jpg"

speckyspooky commented 8 months ago

If you would see a way to give me exactly the part of the report and the folder structure for rebuild on my side (with OS Windows) I could try whether I can get the same issue like you - it is really special and I'm with you, normally there isn't a special value on your file name.

hvbtup commented 8 months ago

Pls keep this issue open for 2 weeks, right now I'm busy and next week I'm on vacation.

speckyspooky commented 7 months ago

Today I tested your constellation with the same logic from your side, created a logos-folder, used dataset on an image and used the same name like your logo-image name to test it. But I cannot produce your error - if I change the logo-file-name to get an unmatched result for the report, an error will be produced but an understandable error instead of yours, my error/stacktrace:

2024-04-07 11_50_04-ws - org eclipse birt report engine_src_org_eclipse_birt_report_engine_api_scrip

The message is okay, because the report-image-path is unequal to the image-file.

hvbtup commented 7 months ago

OK. I'm still busy with other things, and I was able to solve the issue by correcting the file path. While I still don't know what was going on here and I was not able to create reproduce the issue using a simple report, I'll close this issue. Even though we don't know the exact reason of the strange error message, the existence of this issue report might help others in a similar situation.