Check if the stack if empty before pulling from it. 

Check if the stack if empty before pulling from it. Prevent popping element from empty stack.

Signed-off-by: Pengcheng Bian <pbian@actuate.com>