6

I extends MessageCracker Class and override methods(Handlers)

public void onMessage(ExecutionReport execRep, SessionID sessionID)
...
public void onMessage(BusinessMessageReject message, SessionID sessionID)
...
public void onMessage(Quote quote, SessionID sessionID)

each method catch messages extend Message - ExecutionReport, BusinessMessageReject, Quote etc.

All work fine but IntellijIDE say on this methods - Method 'onMessage(quickfix.fix44.Quote, quickfix.SessionID)' is never used

How can I fix it?

glytching
  • 44,936
  • 9
  • 114
  • 120
user5620472
  • 2,722
  • 8
  • 44
  • 97
  • Is the "never used" message appearing on the interface/parent or on the subclass? – glytching Aug 18 '17 at 09:35
  • If these methods are also annotated somehow, You can suppress this warning by that annotation through Alt+Enter and related additional action ( see the answer at https://stackoverflow.com/questions/5283972/telling-intellij-idea-which-methods-not-to-identify-as-unused/5284371#5284371 ) – Nashev Apr 30 '21 at 20:23

1 Answers1

7

IntelliJ is telling you that a public method on your class is unused. It's not an error, it's just an information message.

You could think of it as a gentle hint: by writing a public method you have implied that something should use that method but IntelliJ is unable to find any usages of that method so it warns you just in case either (a) the method scope should be reduced or (b) you have forgotten to write the code which is intended to invoke this method.

You can switch this behaviour on/off from Preferences > Editor > Inspections > Unused Declaration

enter image description here

You can also disable this inspection on a specific method by annotating that method with @SuppressWarnings("unused").

glytching
  • 44,936
  • 9
  • 114
  • 120
  • 2
    There are methods that are not really used and I want to see information about them. But these methods are not explicitly called but used. They receive messages. – user5620472 Aug 18 '17 at 10:11
  • According to IntelliJ's "Unused declaration" inspection these methods are unused. If you disagree with IntelliJ's inspection then you can disable it, see `Preferences > Editor > Inspections > Unused Declaration`. However, it is only an information message, it does not indicate an error so you could also just ignore it. – glytching Aug 18 '17 at 10:13
  • I understand it. Perhaps there is an annotation or a way to mark methods that work like handler – user5620472 Aug 18 '17 at 10:46
  • 3
    You can add the `@SuppressWarnings("unused")` annotation to this method. – glytching Aug 18 '17 at 10:54
  • or (c) these are part of an api that is externally visible to projects depending on your lib. Then again, if you write tests for these the warnings will go away. The issue I run into is that every time I try to commit something I get "you have 7 warnings in this file...are you sure you'd like to commit?" And there could be a valid warning that shows up that I don't notice because of the unused method warnings. – Ben Kushigian May 30 '21 at 01:45