PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] Why does IntelliJ sometimes throw an unused warning but sometimes not?

 April 27, 2022     intellij-idea, java, warnings     No comments   

Issue

I have many Java classes with two constructors:

  1. a private constructor with no arguments and with unused warning suppression called by gson;
  2. a public constructor with arguments.

In one class IntelliJ informs me with a warning that the public constructor is never used. In all other classes there isn't the warning, but if I click Find Usage for the method it displays "Nothing found in project files".

Why is there a warning in some cases and not in others? How can I make IntelliJ always behave in the same way?

This is the class where the public constructor throws the warning:

public class ShopMarketAction extends Action {

    private Boolean inRow = null;
    private Integer index = null;

    @SuppressWarnings("unused") // Called by gson
    private ShopMarketAction() {
        super(ActionType.SHOP_MARKET);
    }

    // THIS METHOD THROWS AN UNUSED WARNING
    public ShopMarketAction(boolean inRow, int index) {
        super(ActionType.SHOP_MARKET);
        this.inRow = inRow;
        this.index = index;
    }

}

This is an example class where the public constructor doesn't throw the warning:

public class ProductionAction extends Action {

    private Integer cardIndex = null;

    @SuppressWarnings("unused") // Called by gson
    private ProductionAction() {
        super(ActionType.PRODUCE);
    }

    // THIS METHOD DOESN'T THROW THE WARNING BUT IS NEVER USED
    public ProductionAction(int cardIndex) {
        super(ActionType.PRODUCE);
        this.cardIndex = cardIndex;
    }

}

I specify that in both classes the method is not used yet.

The Action class that both classes extends:

public abstract class Action {

    @SuppressWarnings({"unused", "FieldCanBeLocal"})
    private final ActionType type; // Used by gson

    protected Action(ActionType type) {
        this.type = type;
    }

}

The ActionType enum:

public enum ActionType {
    SHOP_MARKET, PRODUCE;
}

Warning

No Warning

No Usage


Solution

I found what causes the problem: I have a non-Java file (an UXF file created by another application) which contains the name of all these methods and for some reason IntelliJ consider them as used because of this.



Answered By - Axelitama
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing