Bug 500402 - [CSS] CSS import silently fails
Summary: [CSS] CSS import silently fails
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.6.2   Edit
Assignee: Patrik Suzzi CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
: 430052 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-08-29 05:20 EDT by Stefan Wild CLA
Modified: 2016-09-20 10:07 EDT (History)
4 users (show)

See Also:
Lars.Vogel: review+


Attachments
example project for css import (10.89 KB, application/zip)
2016-09-06 06:10 EDT, Stefan Wild CLA
no flags Details
full exception when launching the applicaition with -consoleLog (2.31 KB, application/octet-stream)
2016-09-08 19:03 EDT, Patrik Suzzi CLA
no flags Details
Archive containing the fixed org.eclipse.e4.ui.css.core project (214.49 KB, application/x-zip-compressed)
2016-09-09 08:36 EDT, Patrik Suzzi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Wild CLA 2016-08-29 05:20:51 EDT
(That's related to 451983 and 429905)

We have css files that import other css files that way:

@import url("colors.css");

Everything's fine when we debug the application from Eclipse. But a built executable application now doesn't have any CSS.
We found out that this import silently fails and only works with

@import url("platform:/plugin/ch.minova.e4.ui.bundle/css/colors.css");

An exception is caught in org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme and cancels the whole CSS parsing. Probably exceptions should be caught in org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.parseStyleSheet, so that all other CSS would be correcty parsed and only the faulty import would be skipped and the error logged.

An additional improvement would avoid the problem I had:
In org.eclipse.e4.ui.css.core.util.impl.resources.ResourcesLocatorManager.resolve three uriResolvers are used. The first is OSGiResourceLocator with startLocation "platform:/plugin/org.eclipse.ui.themes/css/". This should be the bundle where the parsed css file lies, probably additional to the org.eclipse default.

I'm not too deep in this, so I don't dare to provide a gerrit fix.

Greetings,
Stefan
Comment 1 Patrik Suzzi CLA 2016-09-04 06:39:32 EDT
Stefan, would you mind adding a simple project we can use to test and fix the bug?
Comment 2 Stefan Wild CLA 2016-09-06 06:10:13 EDT
Created attachment 263984 [details]
example project for css import

In this sample project you can press a button. If you start this from eclipse neon, on click the theme changes. If you start the exported executable, on click nothing happens.
Comment 3 Patrik Suzzi CLA 2016-09-08 16:44:46 EDT
Stefan, how are you exporting the executable?
Comment 4 Patrik Suzzi CLA 2016-09-08 19:03:51 EDT
Created attachment 264066 [details]
full exception when launching the applicaition with -consoleLog

Reproduced with Eclipse SDK
Version: Oxygen (4.7)
Build id: I20160830-0800
OS: Windows 10, v.10.0, x86_64 / win32

Steps: 
1. download, unzip and import the attached project in your workspace
2. launch from inside your eclipse, and you see it is working without errors
3. export using .product > Eclipse Product Export wizard
4. launch the exported with -consoleLog option. you will see the below exception.

java.net.MalformedURLException
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.parseStyleSheet(AbstractCSSEngine.java:204)
        at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:428)
        at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:389)
        at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.restore(ThemeEngine.java:560)

truncated. see full exception attached
Comment 5 Stefan Wild CLA 2016-09-09 02:00:32 EDT
(In reply to Patrik Suzzi from comment #3)
> Stefan, how are you exporting the executable?

with the project export wizard "Eclipse product"
Comment 6 Stefan Wild CLA 2016-09-09 02:36:21 EDT
(In reply to Patrik Suzzi from comment #4)
> 4. launch the exported with -consoleLog option. you will see the below
> exception.

If I launch with -consoleLog I see the same exception, but not in the created logfile. I didn't expect that.

Maybe we should use the -consoleLog option more often.

The exception says that there was a MalformedURLException while parsing the CSS that was caused by a NullPointerException. I would rather expect a FileNotFoundException or something like that.

Now thanks for this hint.

Nevertheless, would you consider one of my suggested change requests?
Comment 7 Patrik Suzzi CLA 2016-09-09 04:28:00 EDT
(In reply to Stefan Wild from comment #6)
> Nevertheless, would you consider one of my suggested change requests?

Yes, I'm on it now. 

Analyzing the details, 

(0) this is the URL received that fails, note the exclamation mark after .jar:

jar:file:/C:/Users/myusername/Desktop/tmp-y/test_inner/eclipse/plugins/ch.minova.i18n.application_1.0.0.201609090149.jar!/css/default.css

It fails as we get a NPE in the below code: 

// (1) importRule.getHref returns the URL above
String path = getResourcesLocatorManager().resolve((importRule).getHref());

// (2) NPE here as path is null
testFile = new File(new URL(path).getFile());
if (testFile.exists()) {
	url = new URL(path);
}
Comment 8 Eclipse Genie CLA 2016-09-09 08:28:01 EDT
New Gerrit change created: https://git.eclipse.org/r/80791
Comment 9 Patrik Suzzi CLA 2016-09-09 08:36:38 EDT
Created attachment 264076 [details]
Archive containing the fixed org.eclipse.e4.ui.css.core project

To see the solution working, unzip the archive, and replace the "org.eclipse.e4.ui.css.core *" folder in your exported application. 

Please tell if this fixes the issue.
Comment 10 Patrik Suzzi CLA 2016-09-09 08:38:53 EDT
*** Bug 430052 has been marked as a duplicate of this bug. ***
Comment 11 Stefan Wild CLA 2016-09-09 10:35:35 EDT
(In reply to Patrik Suzzi from comment #9)
> Created attachment 264076 [details]
> Archive containing the fixed org.eclipse.e4.ui.css.core project
> 
> To see the solution working, unzip the archive, and replace the
> "org.eclipse.e4.ui.css.core *" folder in your exported application. 

I have no such folder, but the .jar file. I replaced the content of this file with the content of org.eclipse.e4.ui.css.core_0.12.0.201609091415.zip/org.eclipse.e4.ui.css.core_0.12.0.201609091415

> Please tell if this fixes the issue.

I keep getting

java.net.MalformedURLException
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.parseStyleSheet(AbstractCSSEngine.java:204)
        at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.setTheme(ThemeEngine.java:428)
...

Actually I don't get it where the ! comes from.
Loading of default.css is not the problem, but the import of common.css.
Comment 12 Patrik Suzzi CLA 2016-09-09 10:47:24 EDT
We have different versions. I tested on Oxygen. I'm going to merge the change and ask you to test the export and run with tomorrow's N-Build.
After success, we can cherry pick to Neon.
Comment 14 Patrik Suzzi CLA 2016-09-09 18:57:18 EDT
Merged to master. 
You can verify the fix starting from the next nightly build.
Comment 15 Patrik Suzzi CLA 2016-09-11 04:26:17 EDT
The bug is fixed. I think we get benefits backporting this to Neon. 

What Do You Think?
Comment 16 Stefan Wild CLA 2016-09-13 04:00:18 EDT
how can I access the nightly build? http://download.eclipse.org/eclipse/updates/4.7-N-builds?

btw, I would trust you when you say it's fixed.
Comment 17 Lars Vogel CLA 2016-09-13 04:04:54 EDT
(In reply to Stefan Wild from comment #16)
> how can I access the nightly build?

http://download.eclipse.org/eclipse/downloads and select the latest N-build. Today this is N20160911-0220

> btw, I would trust you when you say it's fixed.

Better to test the fix. ;-)
Comment 18 Stefan Wild CLA 2016-09-13 08:50:46 EDT
It works with the Oxygen Nightly :-)
Comment 19 Lars Vogel CLA 2016-09-13 09:31:54 EDT
Thanks Stefan for the validation.
Comment 20 Dani Megert CLA 2016-09-19 08:44:49 EDT
(In reply to Patrik Suzzi from comment #15)
> The bug is fixed. I think we get benefits backporting this to Neon. 
> 
> What Do You Think?

Approved.
Comment 21 Eclipse Genie CLA 2016-09-19 09:07:58 EDT
New Gerrit change created: https://git.eclipse.org/r/81331
Comment 23 Patrik Suzzi CLA 2016-09-20 10:07:25 EDT
The change is now in Neon (R4_6_maintenance)

From the next Release, Neon will resolve .css references inside .jar files.