Skip to content

ScriptException: Exception invoking getScreenX #173

@lucaato

Description

@lucaato

Hi everyone,
I just started using HtmlUnit so I hope I'm not doing anything wrong.
The problem I have is a com.gargoylesoftware.htmlunit.ScriptException when i click on a page button, i debugged the code to see where the exception is generated and i found out that in some cases it's possible that the getStyleAttribute method of the CSSStyleDeclaration class throw an ArrayIndexOutOfBoundsException.
The specific line are theese ones (from 203 to 207 in the CSSStyleDeclaration class):

if (values.length > 3) {
    return values[3];
} else {
    return values.length > 1 ? values[1] : values[0];
}

In some case i get a zero length values array that in the last return line results in an java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0.

This are the variables i see while debugging (if you need other details please just ask 👍):
image

This is the complete exception as logged by HtmlUnit:

mag 17, 2020 6:44:15 PM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException
SEVERE: Error during JavaScript execution
======= EXCEPTION START ========
Exception class=[java.lang.RuntimeException]
com.gargoylesoftware.htmlunit.ScriptException: Exception invoking getScreenX
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:891)
	at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:624)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:820)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:792)
	at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2601)
	at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2594)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:361)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:190)
	at com.gargoylesoftware.htmlunit.html.DomElement.lambda$fireEvent$0(DomElement.java:1463)
	at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:624)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
	at com.gargoylesoftware.htmlunit.html.DomElement.fireEvent(DomElement.java:1463)
	at com.gargoylesoftware.htmlunit.html.DomElement.doClickFireClickEvent(DomElement.java:1131)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1062)
	at com.gargoylesoftware.htmlunit.html.HtmlAnchor.click(HtmlAnchor.java:85)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1002)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:898)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:879)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:860)
	at com.github.lucaa.tools.cloudflare.CloudflareParser.generateApis(CloudflareParser.java:56)
	at com.github.lucaa.tools.cloudflare.Main.main(Main.java:9)
Caused by: java.lang.RuntimeException: Exception invoking getScreenX
	at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:214)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.getValue(ScriptableObject.java:348)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.get(ScriptableObject.java:475)
	at com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.get(SimpleScriptable.java:79)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.getProperty(ScriptableObject.java:2340)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1544)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1525)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.doGetElem(Interpreter.java:2414)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1461)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1009)
	at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
	at net.sourceforge.htmlunit.corejs.javascript.BoundFunction.call(BoundFunction.java:53)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:427)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:340)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3607)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:813)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:876)
	... 24 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.getStyleAttribute(CSSStyleDeclaration.java:465)
	at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.getPaddingLeft(CSSStyleDeclaration.java:1901)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getPaddingLeft(ComputedCSSStyleDeclaration.java:837)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getPaddingLeftValue(ComputedCSSStyleDeclaration.java:1696)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getLeft(ComputedCSSStyleDeclaration.java:1557)
	at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getOffsetLeft(HTMLElement.java:1770)
	at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getPosX(HTMLElement.java:1792)
	at com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent.getScreenX(MouseEvent.java:192)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:188)
	... 40 more
Enclosed exception: 
java.lang.RuntimeException: Exception invoking getScreenX
	at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:214)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.getValue(ScriptableObject.java:348)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.get(ScriptableObject.java:475)
	at com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.get(SimpleScriptable.java:79)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.getProperty(ScriptableObject.java:2340)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1544)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1525)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.doGetElem(Interpreter.java:2414)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1461)
	at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1009)
	at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
	at net.sourceforge.htmlunit.corejs.javascript.BoundFunction.call(BoundFunction.java:53)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:427)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:340)
	at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3607)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:813)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:876)
	at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:624)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:820)
	at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:792)
	at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2601)
	at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2594)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:342)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:361)
	at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:190)
	at com.gargoylesoftware.htmlunit.html.DomElement.lambda$fireEvent$0(DomElement.java:1463)
	at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:624)
	at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
	at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
	at com.gargoylesoftware.htmlunit.html.DomElement.fireEvent(DomElement.java:1463)
	at com.gargoylesoftware.htmlunit.html.DomElement.doClickFireClickEvent(DomElement.java:1131)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1062)
	at com.gargoylesoftware.htmlunit.html.HtmlAnchor.click(HtmlAnchor.java:85)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:1002)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:898)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:879)
	at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:860)
	at com.github.lucaa.tools.cloudflare.CloudflareParser.generateApis(CloudflareParser.java:56)
	at com.github.lucaa.tools.cloudflare.Main.main(Main.java:9)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.getStyleAttribute(CSSStyleDeclaration.java:465)
	at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.getPaddingLeft(CSSStyleDeclaration.java:1901)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getPaddingLeft(ComputedCSSStyleDeclaration.java:837)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getPaddingLeftValue(ComputedCSSStyleDeclaration.java:1696)
	at com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration.getLeft(ComputedCSSStyleDeclaration.java:1557)
	at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getOffsetLeft(HTMLElement.java:1770)
	at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getPosX(HTMLElement.java:1792)
	at com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent.getScreenX(MouseEvent.java:192)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:188)
	... 40 more
== CALLING JAVASCRIPT ==
function () {
    [native code]
}
======= EXCEPTION END ========

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions