This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 289251 - [CSS] Calling Measure.getFloatValue() in CSSSWTEditorWidgets results in IllegalStateException
Summary: [CSS] Calling Measure.getFloatValue() in CSSSWTEditorWidgets results in Illeg...
Status: RESOLVED WORKSFORME
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 0.9   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Remy Suen CLA
QA Contact: Bogdan Gheorghe CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-11 14:54 EDT by Bogdan Gheorghe CLA
Modified: 2019-06-05 07:42 EDT (History)
1 user (show)

See Also:


Attachments
CSSPropertyMarginSWTHandler patch v1 (4.60 KB, patch)
2009-09-13 20:56 EDT, Remy Suen CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bogdan Gheorghe CLA 2009-09-11 14:54:58 EDT
While running the CSSSWTEditorWidgets example with the latest code in HEAD, I get the following error trace by trying to change the font-size in the example:

java.lang.IllegalStateException
	at org.apache.batik.css.parser.CSSLexicalUnit.getFloatValue(Unknown Source)
	at org.eclipse.e4.ui.css.core.impl.dom.Measure.getFloatValue(Measure.java:39)
	at org.eclipse.e4.ui.css.swt.properties.css2.CSSPropertyPaddingSWTHandler.setPadding(CSSPropertyPaddingSWTHandler.java:150)
	at org.eclipse.e4.ui.css.swt.properties.css2.CSSPropertyPaddingSWTHandler.applyCSSPropertyPaddingTop(CSSPropertyPaddingSWTHandler.java:90)
	at org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyPaddingHandler.applyCSSProperty(AbstractCSSPropertyPaddingHandler.java:24)
	at org.eclipse.e4.ui.css.swt.properties.css2.CSSPropertyPaddingSWTHandler.applyCSSProperty(CSSPropertyPaddingSWTHandler.java:31)
	at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyCSSProperty(AbstractCSSEngine.java:659)
Comment 1 Remy Suen CLA 2009-09-11 21:34:13 EDT
Reproduced on my end. The computation of default style declarations seems to be causing problems. The snippet below will demonstrate this, just click the button two or more times (as nothing will happen on the first click). If you swap the applyStyles(Object, boolean, boolean) method around, the exception will not occur.

----------


Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

final CSSEngine engine = new CSSSWTEngineImpl(display);
engine.setErrorHandler(new CSSErrorHandlerImpl());

Button button = new Button(shell, SWT.PUSH);
button.addListener(SWT.Selection, new Listener() {
    public void handleEvent(org.eclipse.swt.widgets.Event event) {
        try {
//          engine.applyStyles(shell, true, false);
            engine.applyStyles(shell, true, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
});

shell.setSize(300, 100);
shell.open();

while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
        display.sleep();
    }
}
display.dispose();
Comment 2 Remy Suen CLA 2009-09-13 20:33:17 EDT
We can prevent this by adding another conditional check at line 609 like so...

-if (oldDefaultStyleDeclaration != null) {
+if (oldDefaultStyleDeclaration != null && !oldDefaultStyleDeclaration.equals(defaultStyleDeclaration)) {

...but that only hides the problem. I have tried rolling back the changes that I introduced in a patch for bug 282575 but the problem doesn't go away so it doesn't look like AbstractCSSEngine is the culprit.
Comment 3 Remy Suen CLA 2009-09-13 20:56:33 EDT
Created attachment 147065 [details]
CSSPropertyMarginSWTHandler patch v1

When push comes to shove, one must climb the stack trace and check the classes one by one. :o

I have confirmed that the regression was introduced by bug 284313 between v1.2 and v1.3 of CSSPropertyMarginSWTHandler.

http://dev.eclipse.org/viewcvs/index.cgi/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyMarginSWTHandler.java?r1=1.2&r2=1.3

Retrieving the value prematurely seems to be the cause behind the exception. I have attached a patch which will revert this by going back to the old behaviour of retrieving the value as late as possible.
Comment 4 Remy Suen CLA 2009-11-25 19:02:14 EST
I'll commit this some time this week.
Comment 5 Remy Suen CLA 2009-11-26 07:55:39 EST
(In reply to comment #4)
> I'll commit this some time this week.

Maybe not, the patch seems to be insufficient now. There are also problems with CSSValueSWTColorConverterImpl now trying to make a colour out of the string "null".
Comment 6 Bogdan Gheorghe CLA 2009-11-26 10:18:42 EST
Remy, the reason I didn't release the patch in yet as it doesn't fix the errors I am seeing in the CSSSWTEditorWidgets example (try switching amongst the various style sheets and you'll see what I mean).

As you noted the default style calculation sets a bunch of properties to null, and the parser dies trying to get a float value from null. The right answer is to improve the default value initialization process, but I guess that in the meantime we can always add a null check.
Comment 7 Remy Suen CLA 2009-11-30 18:06:43 EST
(In reply to comment #6)
> As you noted the default style calculation sets a bunch of properties to null,
> and the parser dies trying to get a float value from null. The right answer is
> to improve the default value initialization process, but I guess that in the
> meantime we can always add a null check.

This is the stack trace where a "null" CSSValue is passed. This is actually instantiated when the style sheet is parsed for the first time. Since the code is coming from Batik's CSS parser, I'm not sure if there's anything that can be done on our end. The workaround described by comment 2 fixes the problem for the examples but it's hard to say what kind of adverse effects it may have. I think we should investigate 0.9 to see if it was broken then (I hope not).

Thread [main] (Suspended (breakpoint at line 38 in CSSPropertyImpl))	
	CSSPropertyImpl.<init>(String, CSSValue, boolean) line: 38	
	CSSDocumentHandlerImpl.getCSSProperty(CSSStyleDeclaration, String, LexicalUnit, boolean) line: 222	
	CSSDocumentHandlerImpl.property(String, LexicalUnit, boolean) line: 216	
	Parser.parseStyleDeclaration(boolean) line: not available	
	Parser.parseStyleDeclarationInternal() line: not available	
	Parser.parseStyleDeclaration(InputSource) line: not available	
	CSSParserImpl(AbstractCSSParser).parseStyleDeclaration(CSSStyleDeclaration, InputSource) line: 98	
	CSSParserImpl(AbstractCSSParser).parseStyleDeclaration(InputSource) line: 78	
	CSSSWTEngineImpl(AbstractCSSEngine).parseStyleDeclaration(InputSource) line: 238	
	CSSSWTEngineImpl(AbstractCSSEngine).parseStyleDeclaration(Reader) line: 213	
	CSSSWTEngineImpl(AbstractCSSEngine).parseStyleDeclaration(String) line: 201	
	CSSPropertyHandlerSimpleProviderImpl.getDefaultCSSStyleDeclaration(CSSEngine, CSSStylableElement, CSSStyleDeclaration, String) line: 272	
	CSSPropertyHandlerSimpleProviderImpl(AbstractCSSPropertyHandlerProvider).getDefaultCSSStyleDeclaration(CSSEngine, Object, CSSStyleDeclaration, String) line: 38	
	CSSSWTEngineImpl(AbstractCSSEngine).getDefaultStyleDeclaration(Object, CSSStyleDeclaration, String) line: 579	
	CSSSWTEngineImpl(AbstractCSSEngine).applyDefaultStyleDeclaration(Object, boolean, CSSStyleDeclaration, String) line: 607	
	CSSSWTEngineImpl(AbstractCSSEngine).applyStyles(Object, boolean, boolean) line: 319	
	CSSEditorSWTWidgets(AbstractCSSEditor).applyStyles(Object) line: 105	
	CSSEditorSWTWidgets(AbstractCSSEditor).applyStyles() line: 124	
	AbstractCSSSWTEditor$3.modifyText(ModifyEvent) line: 266	
	TypedListener.handleEvent(Event) line: 167	
	EventTable.sendEvent(Event) line: 84	
	StyledText(Widget).sendEvent(Event) line: 1050	
	StyledText(Widget).sendEvent(int, Event, boolean) line: 1074	
	StyledText(Widget).sendEvent(int, Event) line: 1059	
	StyledText(Widget).notifyListeners(int, Event) line: 773	
	StyledText.setText(String) line: 9454	
	CSSEditorSWTWidgets(AbstractCSSSWTEditor).setStyleSheetContent(String) line: 581	
	CSSEditorSWTWidgets(AbstractCSSEditor).fillTextareaWithStyleSheetContent(InputStream) line: 157	
	CSSEditorSWTWidgets(AbstractCSSEditor).fillTextareaWithStyleSheetContent(File) line: 129	
	CSSEditorSWTWidgets(AbstractCSSEditor).applyStylesFromSelectedFile() line: 198	
	CSSEditorSWTWidgets(AbstractCSSSWTEditor).createRightPanel(Composite) line: 467	
	CSSEditorSWTWidgets(AbstractCSSSWTEditor).display() line: 148	
	CSSEditorSWTWidgets.main(String[]) line: 116
Comment 8 Remy Suen CLA 2009-11-30 18:18:20 EST
(In reply to comment #7)
> I
> think we should investigate 0.9 to see if it was broken then (I hope not).

I checked out R0_9, closed my HEAD projects, reran the example, it still spits errors out. :(
Comment 9 Remy Suen CLA 2010-01-14 13:55:46 EST
I've added a workaround in the examples. We'll have to defer this.
Comment 10 Dani Megert CLA 2013-06-05 10:57:22 EDT
Removing outdated target milestone.
Comment 11 Eclipse Genie CLA 2019-01-13 13:09:43 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 12 Lars Vogel CLA 2019-06-05 07:42:02 EDT
This is a mass change to close all e4 bugs marked with "stalebug" whiteboard.

If this bug is still valid, please reopen and remove the "stalebug" keyword.