problem access array outside of loop in bash

Below is a test script I was trying to use so that I could understand why the logic was not working in a larger script. While accessing and printing array data inside the while loop, everything is fine. Outside the loop, i guess everything is null?? The for loop that is meant to cycle through the array prints blank lines. The last two test echo statements after the call of the function in the main body also fail to output array information. The file addon_list_one_line.txt is a single line of strings that can be seen during the initial output below.

Can anyone explain to me what is wrong after examining the script and output below?

#!/bin/bash

addon_list=addon_list_one_line.txt

 function test_function {
   cat $addon_list|while read line        
   do
     ADDON=( $line )
     echo "\$line is $line"
     echo "whole array is ${ADDON[@]}"
     echo "first array item is ${ADDON[0]}"
     echo "last array item is ${ADDON[14]}"
   done
   for a in {0..14}
      do
           echo "${ADDON[$a]}"    
      done
}

#main body

test_function
echo "last array item is ${ADDON[14]}"
echo "original_array = ${ADDON[@]}"

output of script:

> ./array_example2.sh ~/scripts/wow_addons
$line is auctioneer recount basic-minimap bison deadly-boss-mods dominos heal-bot-continued holy-power-notifier ice-hud omen-threat-meter postal prat-3-0 quartz quest-helper skada
whole array is auctioneer recount basic-minimap bison deadly-boss-mods dominos heal-bot-continued holy-power-notifier ice-hud omen-threat-meter postal prat-3-0 quartz quest-helper skada
first array item is auctioneer
last array item is skada
printing each array element individually...

last array item is
original_array =

This is a classic shortcoming with bash. Easy solution is to use kshell (ksh) instead. Or you can work round it. Check this thread for a complete discussion

problem access array outside of loop in bash
=> problem access variables in pipes
Use redirect, not pipe. Then works fine.
Bash/ksh makers has ideological difference.

cmd1 | cmd2   

create variable in second process, ofcource not usable in 1st process. After process die, no variables.

Ksh maker like more to support idea of original command process idea, ksh use shared memory to handle variables in this kind of use. Works logically as original idea has to write command line even
some part of commands has done in other process. Variables are problem. How to handle variables in pipe. There is difference between ksh and bash.
=> use io redirect = one process, no problem.

while read line         
do      
  ADDON=( $line )      
  echo "\$line is $line"      
  echo "whole array is ${ADDON[@]}"      
  echo "first array item is ${ADDON[0]}"      
  echo "last array item is ${ADDON[14]}" 
done < $addon_list 

Here is example which show this difference between bash/dash/ksh/sh/...

# testcode, a and b variables have created in pipe = subprocess
a1=11
b1=22
export a1 b1
echo $a1 $b1 | (read a b ; echo $a $b) | xargs echo "ab"  ; echo "a1:$a1 b1:$b1 a:$a b:$b"

Test it:
bash testcode
ksh testcode
...

Thanks for the reply. It was a very simple fix to use the redirect instead of the pipe!

As satisfying as it may be to blame the universe's problems on BASH, nearly any bourne shell except ksh does this.