Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[riena-dev] RienaDefaultLnf considered harmful ?

Hi everybody,

here's something to discuss:

I realized that we a dozen or more potential null-pointer-exceptions
waiting to happen, because of the way we use the RienaDefaultLnf:

Example 1:
boolean on = lnf.getBooleanSetting(LnfKeyConstants.DISABLED_MARKER_ADVANCED);

Example 2:
shellRenderer.setCloseable(lnf.getBooleanSetting(LnfKeyConstants.TITLELESS_SHELL_SHOW_CLOSE));

Example 3:
private int getSwitchterHeight() {
  int margin = LnfManager.getLnf().getIntegerSetting(LnfKeyConstants.SUB_APPLICATION_SWITCHER_HEIGHT);
  return margin;
}

The problem here is that the getXXXSetting methods may return null,
which causes an NPE if used together with auto-boxing (Integer-to-int,
Boolean-to-boolean).

(a) My favorite approach would be to deprecate/remove these methods
and use a second variant that always needs a default value:
lnf.getBooleanSetting(KEY, false); lnf.getIntegerSetting(KEY, 0). We
already have these methods :-)
(b) If we don't go for (a), we have to at least go over all places in
the code and make sure we handle a null return value. However this
will not prevent it from re-happening later.

Looking forward to feedback,
Elias.

-- 
Elias Volanakis | Technical Lead | http://eclipsesource.com
elias@xxxxxxxxxxxxxxxxx | +1 503 929 5537 | @evolanakis


Back to the top