-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[avmfritz] Fixed NPE if temperature, powermeter or switch model is null #1887
Conversation
@cweitkamp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kaikreuzer and @robbyb67 to be potential reviewers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apart from some really minor comments the only thing which I can see prevents this PR to be merged is that it needs a rebase.
@@ -109,6 +110,7 @@ public void initialize() { | |||
public void dispose() { | |||
logger.debug("Handler disposed."); | |||
if (pollingJob != null && !pollingJob.isCancelled()) { | |||
logger.debug("stop polling job"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here something with the indentation went wrong.
import org.openhab.binding.avmfritz.internal.hardware.FritzahaWebInterface; | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some words here would be nice
try { | ||
jaxbc = JAXBContext.newInstance(DevicelistModel.class); | ||
} catch (JAXBException e) { | ||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to add a debug output here, but the method is static and I have no clue how to access the logger from a static methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. That's actually not much different than usual, just use the LoggerFactory:
LoggerFactory.getLogger(FritzAhaXMLCallback.class).debug(/*...*/);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SJKA I assume we are not going to fetch the logger each time but just have a static logger in this case:
As we are in a dynamic OSGi environment, loggers should be non-static, when ever possible and have the name logger.
@SJKA Thanks for your review. I applied your changes. |
Thanks, looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your changes I added some remarks/questions.
try { | ||
jaxbc = JAXBContext.newInstance(DevicelistModel.class); | ||
} catch (JAXBException e) { | ||
LoggerFactory.getLogger(FritzAhaXMLCallback.class).error("{}", e.getMessage(), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better fetch the logger only once and add a meaningful message before quoting the exception its message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot fetch the logger only once here. It is used in a static
method. This is the way to go in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No for this case a static logger is allowed and accepted :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem yes I am sure :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*/ | ||
public static final JAXBContext jaxbContext = initContext(); | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are docblock give this amount of information better leave them out.
* @author Christoph Weitkamp | ||
* | ||
*/ | ||
public class FritzAhaXMLCallback extends FritzAhaReauthCallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What actually changes by adding this class in the hierarchy, it only has a static field which should/could also be called explicitly without extending etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a look at our last conversation here I hope you will understand why I added this new class. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but still you are actually only referring to some static field you don't need to make it part of the class hierarchy in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. What should I do? Remove it and add the static field to the extended class FritzAhaReauthCallback
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so your goal is to have a place to store the static final JAXB_CONTEXT
if there is no proper location I'm okay with creating a dedicated class for it (most likely better than putting it in FritzAhaReauthCallback
) but just make it a static util class and do not put as a parent class to make static field accessible.
Please note that it is also not a callback, so make it live in another package.
Edit: added missing not which does change the message ;-)
public class FritzAhaDiscoveryCallback extends FritzAhaReauthCallback { | ||
public class FritzAhaDiscoveryCallback extends FritzAhaXMLCallback { | ||
/** | ||
* logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no fan of comments which add no value, everyone could have guessed this is a logger :-P
/** | ||
* JAXBContext | ||
*/ | ||
public static final JAXBContext jaxbContext = initContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a constant, please follow the naming conventions and uppercase it.
@cweitkamp is it clear now what changes I expect? Please do not forget to mention us if you force push, because we will not be notified by GitHub in that case |
@martinwv Yes, very clear. I will need a couple of days to apply those changes. Thanks for your support. |
Np you are welcome |
- Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@martinvw I did it. Do you want to have a look? |
Thanks everyone! |
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
* master: (23 commits) Fixes for setting brightness and colour temperature for V3 white bulbs. (openhab#2338) [RFXCOM] Add new protocols (openhab#2331) [RFXCOM] Add support for UV sensors (openhab#2330) Removed the unsupported MACROMAN encoding (openhab#2332) Create Issue and PR template files (openhab#2285) Corrected the discovery of new devices (openhab#2326) Fixes ./, decimal point issue in volume (openhab#2297) Fix table layout feed binding (openhab#2318) When trying to send a message while the bridge was not connected an NPE occurred (openhab#2299) D-Link Smart Home device binding (openhab#2035) Updated README.md, Changed definition of 'battery_low' channel to sytemwide channel type 'system.low-battery' (openhab#2262) Tesla : Move Event Stream to a separate Thread to speed up processing + discard events that are too old to be relevant + clean-up constants (openhab#2307) Fixed NPE if temperature, powermeter or switch model is null (openhab#1887) [DSCAlarm] Various Fixes and Enhancements (openhab#2313) [globalcache] Implement bi-directional support for serial devices (openhab#2311) Keba : Fix kecontact.xml in ESH-INF (openhab#2314) Keba : Fixes openhab#2237 openhab#2236 openhab#2234 openhab#2038 (openhab#2270) Fixed typo in configuration of channel-type-id (openhab#2310) Update native AllJoyn library for linux x86 and x64 (openhab#2308) [kodi] Added channels for opening PVR TV or Radio streams (openhab#2084) ...
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…#1887) - Added some more debug loggings - Added additional xml-element tags for creating objects by JAXBContext - Refactoring the use of JAXBContext as singleton instance to prevent memory leaks Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Closes #1885
Signed-off-by: Christoph Weitkamp github@christophweitkamp.de