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

Plugin classes refactor #3

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Plugin classes refactor #3

wants to merge 13 commits into from

Conversation

@desyncr
Copy link
Author

desyncr commented Oct 18, 2021

Few notes:

In 909858d:

    Service connectionService = discoverConnectionService(device);
    if (commonService == null) {
        return;
    }

The IDE indicates that commonService == null is always false. Not sure how it comes up with that as discoverConnectionService clearly returns a NULL under certain conditions.

In 646ead5:

    Map<String, StateVariableValue<?>> values = sub.getCurrentValues();

The IDE indicates that it's an "unchecked assignment: Reason: 'sub' has raw type, so result of getCurrentValues is erased".

@desyncr
Copy link
Author

desyncr commented Nov 5, 2021

@ArneBab @Bombe Let me know how it looks!

@ArneBab
Copy link

ArneBab commented Jun 18, 2022

@Bombe is this good to go now?

1 similar comment
@ArneBab
Copy link

ArneBab commented Nov 28, 2022

@Bombe is this good to go now?

@Bombe
Copy link

Bombe commented Dec 11, 2022

Few notes:

In 909858d:

    Service connectionService = discoverConnectionService(device);
    if (commonService == null) {
        return;
    }

The IDE indicates that commonService == null is always false. Not sure how it comes up with that as discoverConnectionService clearly returns a NULL under certain conditions.

Sure, but connectionService is not actually checked for null here. commonService, however, was already found to be non-null a couple of lines earlier so your IDE is quite right in this case. :)

@Bombe
Copy link

Bombe commented Dec 12, 2022

And for this one:

In 646ead5:

    Map<String, StateVariableValue<?>> values = sub.getCurrentValues();

The IDE indicates that it's an "unchecked assignment: Reason: 'sub' has raw type, so result of getCurrentValues is erased".

Yes, sub is a GENASubscription (as per the inherited method from SubscriptionCallback) and GENASubscription is supposed to have a type parameter. As a consequence of that sub.getCurrentValues() won’t have any type parameters which is far less problematic than the other issue. :)

We could check whether a newer version of cling (2.1.2 is available, we’re using 2.1.0) has type parameters in its method declarations; other than that there’s little we can do. Cast it, ignore it, either would be fine with me.

Copy link

@Bombe Bombe left a comment

Choose a reason for hiding this comment

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

I haven’t delved into the UPnP protocol at all, all the synchronous network communication seems really weird to me but I’m assuming it works. 🙂

Service connectionService;
if ((connectionService = discoverConnectionService(device)) == null) return;
Service connectionService = discoverConnectionService(device);
if (commonService == null) {
Copy link

Choose a reason for hiding this comment

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

As already mentioned in the other comment, this needs to be connectionService == null.

Service connectionService;
if ((connectionService = discoverConnectionService(device)) == null) return;
Service connectionService = discoverConnectionService(device);
if (commonService == null) {
Copy link

Choose a reason for hiding this comment

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

Dito.

});
}

private UpnpService upnpService;
Copy link

Choose a reason for hiding this comment

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

This should be final.

});
}

private ServiceManager serviceManager;
Copy link

Choose a reason for hiding this comment

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

Member variables initialized in the constructor should be final.


serviceManager.waitForBooting();

synchronized (this) {
Copy link

Choose a reason for hiding this comment

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

Which of the members in this synchronized are actually protected by it? Every single one of them is also used without a synchronized block, so it’s either unnecessary or broken. :)

public Collection<DetectedIP> getExternalIPs() {
waitForBooting();

if (connectionServices.size() == 0) {
Copy link

Choose a reason for hiding this comment

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

Please use connectionService.isEmpty(), it’s way more descriptive.

*/
private void realGetExternalIPs() {

if (connectionServices.size() == 0) {
Copy link

Choose a reason for hiding this comment

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

This is unnecessary. connectionService is already checked for being empty before this method is called, and it’s called from nowhere else.


waitForBooting();

if (connectionServices.size() < 0 && commonServices.size() < 0) {
Copy link

Choose a reason for hiding this comment

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

This doesn’t make any sense. Collections can never have negative sizes.

return new IGDRates(upRatesSum, downRatesSum);
}

// We get nothing from GetLinkLayerMaxBitRates. Try GetCommonLinkProperties
Copy link

Choose a reason for hiding this comment

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

This is almost a duplicate of the first half of this method. It should be possible to extract the logic so it’s in a single place.


// We get nothing from GetLinkLayerMaxBitRates. Try GetCommonLinkProperties

final List<Integer> upRates2 = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

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

Just clear() the other lists, declaring a second set of them is unnecessary.

Copy link

Choose a reason for hiding this comment

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

(And this might just go away if the common logic can be extracted, anyway. 🙂)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants