Adobe-Runtime-Support
Adobe-Runtime-Support copied to clipboard
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 3737
Hi Andrew,
Just got this bug today when debugging my App:
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 3737 at flash.tools.debugger.concrete.ScriptText.getLine(ScriptText.java:38) at flash.tools.debugger.concrete.DModule.getLine(DModule.java:135) at flex.tools.debugger.cli.DebugCLI.dumpBreakLine(DebugCLI.java:2485) at flex.tools.debugger.cli.DebugCLI.dumpHaltState(DebugCLI.java:2289) at flex.tools.debugger.cli.DebugCLI.runningLoop(DebugCLI.java:2821) at flex.tools.debugger.cli.DebugCLI.process(DebugCLI.java:817) at flex.tools.debugger.cli.DebugCLI.execute(DebugCLI.java:669) at flex.tools.debugger.cli.DebugCLI.main(DebugCLI.java:461)
Then I got this Error from AS3 in console:
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.
I am using IntelliJ.
I am using SDK 51.1.5.
I have tried this with SDK 51.1.3.10 as well but same error happens.
I am using:
Windows 11 Pro. javac 11.0.12
java version "1.8.0_311" Java(TM) SE Runtime Environment (build 1.8.0_311-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)
Any ideas what might cause this?
Interesting! And this is repeatable then? Is it related to a particular breakpoint that you have set up in your code? Seems like the debugger is getting a bad index (I don't suppose your AS3 file is particularly massive? or, do you use any of the newer AS3 null-based operations like ?. or ?? (I'm wondering if the compiler hadn't set up line numbering properly for those..)
If we look at the ScriptText.getLine() method, I would put money on this being where the input lineNum is zero, index is then -1, and this is doubled for use in an array lookup hence the -2 in the error. It looks like there should have been some error handling (see the commented-out throw command) or perhaps that should be in the function that calls this, which already checks that the index is not too large..
But the root cause is likely to be a "debugline 0" command in your SWF which may be triggering the exception. Some of the compiler outputs don't have line information so would put in a zero, but normally that's ignored because these things tend to all be on a single line so we get a line number from another statement on the same source code line.
We can check on this to see if we can reproduce it and if so, maybe patch the compiler. Or the debugger!
Whether this is then affecting the subsequent 1009 TypeError, I'm not sure; do you know if that is still thrown if you run without a debugger?
thanks
Yes I can reproduce it 100%.
I don't know it is very weird. I am returning null from a function like this:
public function createFiltersFromData(filterData:Object, filtersOrderList:Array, cache:Boolean = false):FilterChain
{
filtersList.length = 0;
createFilters(filterData, filtersOrderList);
if(filtersList.length === 0)
{
return null; // here I return null
}
else
{
// else code here...
}
}
And I am setting return value of that function to another getter like this:
(object.previewObject as ColorObjectBase).colorDetailFilter = _levelFiltersModel.createFiltersFromData()
That getter has signature like this:
public function set colorDetailFilter(value:FilterChain):void{}
But what's weird about it is that it crashes when I click 'Step into' when it reaches return null;
So it looks like it crashes because of returning null in createFiltersFromData not because I am setting null to colorDetailFilter getter.
Also filtersOrderList is empty here which is a bug on my game logic but filtersOrderList is passed on to the createFilters() that has this:
var filtersCreatedCount:int = filtersList.length;
for(var i:int = 0, len:int = filtersOrderList.length; i < len; i++)
I don't know if somehow context is not switched between function calls.
It is very weird because this happens on second attempt because I have 2 objects with the same state and first time there is no error when I return null but second time it is.
And I am not using null-based operations like ?. or ??
HI @ajwfrost,
I am getting this error now with different AS3 function:
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 3679 at flash.tools.debugger.concrete.ScriptText.getLine(ScriptText.java:38) at flash.tools.debugger.concrete.DModule.getLine(DModule.java:135) at flex.tools.debugger.cli.DebugCLI.dumpBreakLine(DebugCLI.java:2485) at flex.tools.debugger.cli.DebugCLI.dumpHaltState(DebugCLI.java:2289) at flex.tools.debugger.cli.DebugCLI.runningLoop(DebugCLI.java:2821) at flex.tools.debugger.cli.DebugCLI.process(DebugCLI.java:817) at flex.tools.debugger.cli.DebugCLI.execute(DebugCLI.java:669) at flex.tools.debugger.cli.DebugCLI.main(DebugCLI.java:461)
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hi - looks like we'd dropped this thread, sorry. Would it be possible to get your SWF file so that we can check the debug information within it? (let me know if you want a private upload link...)
thanks
Hi @ajwfrost,
My swf is very big 17MB :D
Is there any log that ADL produces that I can give you?
I had been thinking of opening it in SWF Investigator, dumping the decompiled actionscript bytecode into a text editor, and searching for a 'debugline 0' or similar... this is one way to find out if that's the root cause; the other of course would be to see whether we get that instruction from the SWF File when running, and if we did that we could also see whether it's possible to work around the problem...
You mention you're on Windows - is it the default 32-bit ADL/AIR runtime that you're using? And what version of the SDK are you currently using, we can rebuild on that with some extra command-line output that triggers if we hit this kind of issue..
thanks
This happens when I try to access null object property with int variable like this:
_colorDetailStateFilter[_colorObjectCurrentState]
Here _colorDetailStateFilter is null and _colorObjectCurrentState has value of 1
_colorDetailStateFilter is object and _colorObjectCurrentState is int