class Test { void test(String s) { final String x = s == null ? "" : s.trim().substring(1), y = x.replace("foo", "bar"); System.out.println(x); } }