animationClip.events.length>1 but animationClip.events[0] report NullReferenceException??why?

With unity 5

Debug.Log(“clip.events.len=” + clip.events.Length);
print result is 1

Debug.Log(clip.events[0]);
is report
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Debug.Log (System.Object message) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebug.gen.cs:84)

WHY???

just because an array is 1 slot in length doesn’t mean there is anything in that slot.

His code shouldn’t raise a NullReferenceException in that case, though. “(null).ToString()” does not raise an exception.
“Debug.Log(clip.events[0])” should only raise an exception if “clip” is null.

Edit: Correction - Of course “(null).ToString()” does raise an exception. I was more on the use case of "Debug.Log(“test: " + (nullVariableHere))”, which doesn’t.

how are you accessing the animationClip? are you retrieving it from the Animator component via GetCurrentAnimatorClipInfo()?

I’ve been playing with that a little just now and it looks like it only returns a value inside Update() and not Start() or Awake()… and it appears to not return a value in the first frame.
Project has an empty gameobject with a meshsphere as a child, all scripts/animators are on the parent, animation is the sphere child moving between y=0 and y=1 on loop. Event was added which changes the meshRenderer.material.color to a random colour at the top.

I ran

    void Start()
    {
        anim = GetComponent<Animator>();
    }

    void Update () 
    {
        Debug.Log(anim.GetCurrentAnimatorClipInfo(0).Length);
    }

and it returned

0
UnityEngine.Debug:Log(Object)
testingscript:Update() (at Assets/testingscript.cs:19) (x1)
1
UnityEngine.Debug:Log(Object)
testingscript:Update() (at Assets/testingscript.cs:19) (x1149)