Fixing several bugs in java backend

This pull request is separated from my work on removing redundant configuration cells. Several bugs were revealed after the optimization. It's interesting that none of the semantics in our regression test suite except simple-typed-static was able to catch the bug.

@dwightguth @andreistefanescu please review