Skip to content

Attepted fix of NPE in #1783#1786

Merged
RHenigan merged 7 commits intodevelopfrom
bugfix/issue_1783
Feb 8, 2022
Merged

Attepted fix of NPE in #1783#1786
RHenigan merged 7 commits intodevelopfrom
bugfix/issue_1783

Conversation

@noah-livio
Copy link
Contributor

@noah-livio noah-livio commented Jan 25, 2022

Fixes #1783

This is not ready for review.

Risk

None

Testing Plan

  • I have verified that I have not introduced new warnings in this PR (or explain why below)
  • I have run the unit tests with this PR
  • I have tested this PR against Core and verified behavior (if applicable, if not applicable, explain why below).
  • I have tested Android, Java SE, and Java EE

Unit Tests

testDisposeAfterRetryChangeRegistration() - Creates a sample SdlManager, calls retryChangeRegistration() and then calls dispose(). This test will pass if no exceptions are thrown.

testRetryChangeRegistrationAfterDispose() - Creates a sample SdlManager, calls dispose() and then calls retryChangeRegistration(). This test will pass if no exceptions are thrown.

Core Tests

Both Core tests were performed in a modified version of Hello Sdl Android, while locally making retryChangeRegistration() public so it can be directly called in the app.

  1. At the end of SdlService.performWelcomeShow() I called sdlManager.retryChangeRegistration() then sdlManager.dispose(). As a result, the app did not crash and SdlManager did not throw a visible exception.

  2. At the end of SdlService.performWelcomeShow() I called sdlManager.dispose() then sdlManager.retryChangeRegistration(). As a result, the app did not crash and SdlManager did not throw a visible exception.

Core version / branch / commit hash / module tested against: SDL Core v8.0.0 master 68f082169e0a40fccd9eb0db3c83911c28870f07
HMI name / version / branch / commit hash / module tested against: Generic HMI v0.11.0 master 47e0ad42f05b27adff61befd864e79c2ab4b8cec

Summary

Converts local variable handler in SdlManager.retryChangeRegistration() to a private member of the class
Creates private member changeRegistrationRunnable to replace anonymous Runnable in SdlManager.retryChangeRegistration()

Add DebugTool warning in the default constructor of SdlManager to let developers know not to use the constructor directly.

In SdlManager.dismiss(), remove changeRegistrationRunnable from handler if both are not null

In BaseSdlManager.checkLifecycleConfiguration() add a null check for managerListener

Changelog

Breaking Changes
  • None
Enhancements
  • None
Bug Fixes

CLA

@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #1786 (04ec0e3) into develop (039503d) will increase coverage by 0.05%.
The diff coverage is 30.59%.

❗ Current head 04ec0e3 differs from pull request most recent head e816eec. Consider uploading reports for the commit e816eec to get more accurate results

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #1786      +/-   ##
=============================================
+ Coverage      54.36%   54.42%   +0.05%     
- Complexity      5513     5522       +9     
=============================================
  Files            562      562              
  Lines          25516    25543      +27     
  Branches        3319     3328       +9     
=============================================
+ Hits           13872    13901      +29     
  Misses         10382    10382              
+ Partials        1262     1260       -2     
Impacted Files Coverage Δ
...icelink/managers/lockscreen/LockScreenManager.java 46.74% <0.00%> (ø)
...tdevicelink/managers/video/VideoStreamManager.java 22.40% <0.00%> (ø)
...managers/video/resolution/VideoStreamingRange.java 52.72% <0.00%> (ø)
...icelink/transport/MultiplexBluetoothTransport.java 4.23% <ø> (ø)
...martdevicelink/transport/SdlBroadcastReceiver.java 3.04% <0.00%> (ø)
...om/smartdevicelink/transport/SdlRouterService.java 11.09% <ø> (ø)
...artdevicelink/transport/utl/SdlDeviceListener.java 7.93% <0.00%> (ø)
...in/java/com/smartdevicelink/util/AndroidTools.java 20.89% <0.00%> (ø)
...a/com/smartdevicelink/managers/BaseSdlManager.java 49.24% <0.00%> (-0.57%) ⬇️
...tdevicelink/managers/file/UploadFileOperation.java 67.83% <0.00%> (ø)
... and 31 more

Add another check in case the manager listener is never instantiated
Also make SdlManager default constructor package private
Also add debug warning about using the constructor outside the builder
@noah-livio noah-livio marked this pull request as ready for review January 27, 2022 21:02
}
} else {
DebugTool.logError(TAG, "Change Registration onError: " + response.getResultCode() + " | Info: " + response.getInfo());
retryChangeRegistration();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this code was missed, this should not be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

SdlManager sdlManager = createSampleManager("Test App", "test.test.test", lockScreenConfig);
sdlManager.dispose();
sdlManager.retryChangeRegistration();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think these unit tests actually will catch what we are trying to prevent. If the checkLifecycleConfiguration method is updated to manually throw an exception these tests will still pass. It does not look like the code is waiting for the runnable to complete so I believe the tests are completing before the runnable even executes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think I should just remove them then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I dont believe these tests are needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will do

};

public SdlManager(){
DebugTool.logWarning(TAG, "If this SdlManager was created without using SdlManager.Builder, most of its members are not initialized");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
DebugTool.logWarning(TAG, "If this SdlManager was created without using SdlManager.Builder, most of its members are not initialized");
DebugTool.logWarning(TAG, "SdlManager must be created with SdlManager.Builder");

@noah-livio
Copy link
Contributor Author

Fixes #1783

This is not ready for review.

Risk

None

Testing Plan

  • I have verified that I have not introduced new warnings in this PR (or explain why below)
  • [] I have run the unit tests with this PR - None
  • I have tested this PR against Core and verified behavior (if applicable, if not applicable, explain why below).
  • I have tested Android, Java SE, and Java EE

Unit Tests

  • None

Core Tests

Both Core tests were performed in a modified version of Hello Sdl Android, while locally making retryChangeRegistration() public so it can be directly called in the app.

  1. At the end of SdlService.performWelcomeShow() I called sdlManager.retryChangeRegistration() then sdlManager.dispose(). As a result, the app did not crash and SdlManager did not throw a visible exception.

  2. At the end of SdlService.performWelcomeShow() I called sdlManager.dispose() then sdlManager.retryChangeRegistration(). As a result, the app did not crash and SdlManager did not throw a visible exception.

Core version / branch / commit hash / module tested against: SDL Core v8.0.0 master 68f082169e0a40fccd9eb0db3c83911c28870f07
HMI name / version / branch / commit hash / module tested against: Generic HMI v0.11.0 master 47e0ad42f05b27adff61befd864e79c2ab4b8cec

Summary

Converts local variable handler in SdlManager.retryChangeRegistration() to a private member of the class
Creates private member changeRegistrationRunnable to replace anonymous Runnable in SdlManager.retryChangeRegistration()

Add DebugTool warning in the default constructor of SdlManager to let developers know not to use the constructor directly.

In SdlManager.dismiss(), remove changeRegistrationRunnable from handler if both are not null

In BaseSdlManager.checkLifecycleConfiguration() add a null check for managerListener

Changelog

Breaking Changes
  • None
Enhancements
  • None
Bug Fixes

CLA

@RHenigan RHenigan merged commit b51cda0 into develop Feb 8, 2022
@RHenigan RHenigan deleted the bugfix/issue_1783 branch February 8, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants