Safer casting in java config parsing