12

I am getting following option like "Add method contract to 'setDisplayHomeAsUpEnabled'", I know that inspection is because of NPE can throw by getSupportActionBar() but I want to know actual use of Method Contract

enter image description here

If I Press Enter on that selection, I am getting:

enter image description here

Any Sharing? Any Help? It will appreciated :)

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • it's just a warning message or suggestion by studio ,plz refer this http://stackoverflow.com/questions/29786011/how-to-fix-getactionbar-method-may-produce-java-lang-nullpointerexception – Radhey Mar 16 '16 at 06:50
  • 1
    @Radhe I know that, I am asking for `Add method contract to....` – Pratik Butani Mar 16 '16 at 06:58
  • Just ftr, I've happen to stumble upon "get method contract...", so clicked on it out of curiosity. I've got the first dialog, clicked OK, then clicked Cancel on the next dialog. No idea why, but next thing I know, everything is slow as if I had like 2Kb of RAM, not to mention AS took about 5min to close, I had to shutdown the PC, it took forever to restart... Something wen't terribly wrong because of this thing. – 101is5 Dec 27 '21 at 21:37

1 Answers1

10

This relates to creating method contracts that describe when a method may return null or not null.

IntelliJ/Android Studio is sometimes able to to infer this from the context of the code. But when it is not able to know for sure, you can specify a method contract that tells the caller what will happen in different circumstances.

Read more about method contracts here.

Bö macht Blau
  • 12,820
  • 5
  • 40
  • 61
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441