Consider the source code that defines the new String array:
return new String[] { getUserFullName(), StringUtil.formatDate(sent), tiltu, StringUtil.initCap(user.getName()), vuosi.toString(), asiatyyppi[0] + " " + lisatiedot[0], asiatyyppi[1] + " " + lisatiedot[1], alaviitteet[0], alaviitteet[1]}; }
If any of the elements of the built-in array should NullPointerException , the JVM will interpret the Exception as having occurred in the line where the definition started. In other words, the JVM will consider the above code as the following:
return new String[] { getUserFullName(), StringUtil.formatDate(sent), tiltu, StringUtil.initCap user.getName()), vuosi.toString(), asiatyyppi[0] + " " + lisatiedot[0], asiatyyppi[1] + " " + lisatiedot[1], alaviitteet[0], alaviitteet[1]}; }
where everything is on the same line.
If you really want to handle a NullPointerException here, you must define the variables outside of creation.
Tim biegeleisen
source share