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

NonStaticMethodCheck complains about methods that just throw an exception #623

Closed
HDouss opened this issue Jan 17, 2016 · 43 comments
Closed
Assignees
Labels

Comments

@HDouss
Copy link
Contributor

HDouss commented Jan 17, 2016

NonStaticMethodCheck complains about methods that only throws an exception. This could be fine in cases where a class implementation have a "not yet" supported feature or a serializable object that does not support readObject/writeObject where the method have just to throw an appropriate exception. Example:

private void writeObject(final ObjectOutputStream stream)
    throws NotSerializableException {
    throw new NotSerializableException(AggregateException.class.getName());
}
@mkordas
Copy link
Contributor

mkordas commented Jan 17, 2016

@HDouss but then method has '@OverRide' and is excluded from check, right? Please provide an example.

@HDouss
Copy link
Contributor Author

HDouss commented Jan 17, 2016

@mkordas You are right, I update description to give another example.

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss If you gave an example please show it, if not please close this issue

@HDouss
Copy link
Contributor Author

HDouss commented Jan 21, 2016

@krzyk The examples are in the description:

This could be fine in cases where a class implementation have a "not yet" supported feature or a serializable object that does not support readObject/writeObject where the method have just to throw an appropriate exception

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss but such methods are not correct ones, so the appropriate way of dealing with this is adding an exclude. readObject/writeObject shouldn't be implemented if there is no state.

@HDouss
Copy link
Contributor Author

HDouss commented Jan 21, 2016

@krzyk But NonStaticMethodCheck should alert the developer about methods that are not declared as static but are in fact static. For example:

private void writeObject(final ObjectOutputStream stream)
        throws NotSerializableException {
        throw new NotSerializableException(AggregateException.class.getName());
    }

Why such a method should be static ?

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss OK, so you are saying that we should exclude the readObject() and writeObject() methods or some other general rule?

@HDouss
Copy link
Contributor Author

HDouss commented Jan 21, 2016

@krzyk I would say that in general, if a method just throws an exception shouldn't be considered as static.

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss please update the description with that clarification

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss method that only throws exception

@HDouss
Copy link
Contributor Author

HDouss commented Jan 21, 2016

@krzyk Done.

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss also add an example code, it will be easier to understand and implement

@HDouss
Copy link
Contributor Author

HDouss commented Jan 21, 2016

@krzyk First sentence:

NonStaticMethodCheck complains about methods that only throws an exception

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@HDouss yes, I noticed that later :), but example would make it even better.
Could you add an example method that shouldn't cause NonStaticMethodCheck to complain?

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@davvd valid bug

@krzyk
Copy link
Collaborator

krzyk commented Jan 21, 2016

@davvd this is postponed

@davvd davvd added the bug label Jan 21, 2016
@davvd
Copy link

davvd commented Jan 21, 2016

@davvd valid bug

@krzyk tagged this issue with "bug"

@davvd
Copy link

davvd commented Jan 22, 2016

@davvd this is postponed

@krzyk OK, I put "postponed" label here

@davvd
Copy link

davvd commented Jan 22, 2016

@davvd this is postponed

@krzyk right, I'll try to find someone else for this task

@davvd
Copy link

davvd commented Jan 22, 2016

@HDouss thanks for reporting! I topped your account for 15 mins, transaction 75228386

@davvd davvd added DEV labels Jan 22, 2016
@krzyk
Copy link
Collaborator

krzyk commented Jan 26, 2016

@davvd this is not postponed

@davvd
Copy link

davvd commented Jan 26, 2016

@davvd this is not postponed

@krzyk got it, "postponed" tag removed from here

@davvd davvd removed the postponed label Jan 26, 2016
@krzyk
Copy link
Collaborator

krzyk commented Jan 28, 2016

@davvd assign @kitsook

@kitsook
Copy link
Contributor

kitsook commented Jan 28, 2016

@krzyk @davvd i am not taking new tasks at the moment. please assign to someone else

@krzyk
Copy link
Collaborator

krzyk commented Jan 29, 2016

@kitsook OK, I'll reassign

@krzyk
Copy link
Collaborator

krzyk commented Jan 29, 2016

@davvd please assign @gumbelmj

@davvd
Copy link

davvd commented Jan 29, 2016

@davvd assign @kitsook

@krzyk done. @kitsook the task is yours, please go ahead

@davvd
Copy link

davvd commented Jan 29, 2016

@davvd please assign @gumbelmj

@krzyk sure! @gumbelmj the task is yours, please go ahead

@gumbelmj
Copy link
Contributor

@davvd the pull request has been submitted.

@gumbelmj
Copy link
Contributor

gumbelmj commented Feb 2, 2016

@HDouss can you close this issue as it has been fixed? Thanks.

@HDouss
Copy link
Contributor Author

HDouss commented Feb 2, 2016

@gumbelmj it seems that the implementation also excludes such cases:

    private void data(final String input) {
        try {
            Class.someStaticMethod(input);
        } catch (final IOException ex) {
            throw new IllegalStateException(ex);
        }
    }

The example above is a true positive (i.e it should raise a complaint by NonStaticMethodCheck), but your implementation is discarding it.

@krzyk
Copy link
Collaborator

krzyk commented Feb 2, 2016

@HDouss I don't think this is a good case, if there is such method it should be definitely static (unless it is an @Override method).

@HDouss
Copy link
Contributor Author

HDouss commented Feb 2, 2016

@krzyk This is what I said

The example above is a true positive (i.e it should raise a complaint by NonStaticMethodCheck)

But the solution provided by the PR will exclude such case.

@HDouss
Copy link
Contributor Author

HDouss commented Feb 2, 2016

@krzyk It will exclude it from the check, but it shouldn't. Such case should make qulice raise an issue.

@krzyk
Copy link
Collaborator

krzyk commented Feb 2, 2016

@HDouss Sorry, you are right ( I must learn not to read on the phone :) ).

@gumbelmj
Copy link
Contributor

gumbelmj commented Feb 3, 2016

@krzyk I saw you deployed the changes. Should I continue to address @HDouss concerns?

@krzyk
Copy link
Collaborator

krzyk commented Feb 3, 2016

@gumbelmj yes you should, deploy is just to finish the PR, you will need to create a new one.

@davvd
Copy link

davvd commented Feb 4, 2016

@davvd the pull request has been submitted.

@gumbelmj OK

@krzyk
Copy link
Collaborator

krzyk commented Feb 7, 2016

@gumbelmj please add reference to the pull requests here

@gumbelmj
Copy link
Contributor

gumbelmj commented Feb 8, 2016

@krzyk I updated pull request #685 to count the number of semi-colons instead of the number of lines. I also added another test case.

@gumbelmj
Copy link
Contributor

gumbelmj commented Feb 8, 2016

@HDouss this has been merged again. Are you satisfied with the code now?

@HDouss
Copy link
Contributor Author

HDouss commented Feb 8, 2016

@gumbelmj Thanks

@HDouss HDouss closed this as completed Feb 8, 2016
@davvd
Copy link

davvd commented Feb 10, 2016

@gumbelmj Thank you, I have added 30 mins to your account in payment/transaction "AP-61V51661VF813222P", time consumed: 261 hours and 29 mins... +30 added to your rating, at the moment it is: -30

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

No branches or pull requests

6 participants