Skip to content
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

Merged
merged 1 commit into from
May 29, 2017

Conversation

cweitkamp
Copy link
Contributor

@cweitkamp cweitkamp commented Feb 12, 2017

  • 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

Closes #1885

Signed-off-by: Christoph Weitkamp github@christophweitkamp.de

@mention-bot
Copy link

@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.

@cweitkamp cweitkamp changed the title Fixed NPE if temperature, powermeter or switch model is null (see issue #1885) [avmfritz] Fixed NPE if temperature, powermeter or switch model is null (see issue #1885) Feb 14, 2017
Copy link

@sjsf sjsf left a 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");
Copy link

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;

/**
*
Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

@cweitkamp cweitkamp Apr 5, 2017

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.

Copy link

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(/*...*/);

Copy link
Member

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.

@cweitkamp
Copy link
Contributor Author

@SJKA Thanks for your review. I applied your changes.

@sjsf
Copy link

sjsf commented Apr 11, 2017

Thanks, looks good to me.
@robbyb67 do you want to have a second look since you wrote the binding?

Copy link
Member

@martinvw martinvw left a 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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry to ask again: Are you sure? Have a look at this comment. @SJKA recommended me to do so. And I followed this discussion yesterday - ok, it was in ESH repo, but maybe it ist true for this repo.

Copy link
Member

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 :-)

Copy link
Member

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();

/**
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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. ;-)

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

@martinvw martinvw May 24, 2017

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
Copy link
Member

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();
Copy link
Member

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.

@martinvw
Copy link
Member

@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

@cweitkamp
Copy link
Contributor Author

@martinwv Yes, very clear. I will need a couple of days to apply those changes. Thanks for your support.

@martinvw
Copy link
Member

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>
@cweitkamp
Copy link
Contributor Author

@martinvw I did it. Do you want to have a look?

@martinvw martinvw requested a review from kaikreuzer May 29, 2017 19:53
@kaikreuzer kaikreuzer merged commit 3fc0307 into openhab:master May 29, 2017
@kaikreuzer
Copy link
Member

Thanks everyone!

@cweitkamp cweitkamp deleted the bugfix-1885 branch May 29, 2017 21:04
falkena pushed a commit to falkena/openhab-addons that referenced this pull request Jun 2, 2017
…#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>
holmes added a commit to holmes/openhab2-addons that referenced this pull request Jun 8, 2017
* 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)
  ...
@martinvw martinvw changed the title [avmfritz] Fixed NPE if temperature, powermeter or switch model is null (see issue #1885) [avmfritz] Fixed NPE if temperature, powermeter or switch model is null Jun 25, 2017
@martinvw martinvw added this to the 2.1 milestone Jun 25, 2017
@martinvw martinvw added the bug An unexpected problem or unintended behavior of an add-on label Jun 25, 2017
qvistgaard pushed a commit to qvistgaard/openhab2-addons that referenced this pull request Jun 30, 2017
…#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>
reyem pushed a commit to reyem/openhab2-addons that referenced this pull request Jul 1, 2017
…#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>
Markinus pushed a commit to Markinus/openhab2-addons that referenced this pull request Jul 2, 2017
…#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>
ppieczul pushed a commit to ppieczul/openhab2-addons that referenced this pull request Jul 2, 2017
…#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>
reyem pushed a commit to reyem/openhab2-addons that referenced this pull request Jul 3, 2017
…#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>
aogorek pushed a commit to aogorek/openhab2-addons that referenced this pull request Jul 5, 2017
…#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>
Markinus pushed a commit to Markinus/openhab2-addons that referenced this pull request Sep 8, 2017
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants