NPE fix in molecular formula manipulator.

One commit highlights the bug. The second commit fixes the cause.