IDEA Gives warning 'some variable always false'?

138
May 11, 2019, at 9:30 PM

I wrote following code fragment with loop.But when Variable 'X' given always 'false' in IDEA , this line

final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X);

I need some explain it is not necessary put that or condition there.

    boolean isFirstDose = true;
    boolean isFirstDoseIsPeriodicOrWholePRNOrEoOrOneOff = false;
    for (final DDT: dd)
    {
      final boolean X=
        DosageToolkit.INSTANCE.hasEOTypeDosage(new DoseDetailMutableDTOToBaseDoseDetailAdapter(dd));
      final boolean isOneOffDose = CommonToolkit.INSTANCE.isOneOffDose(dd);
      if (dd.isWholeWhenNeeded() || X|| isOneOffDose)
      {
        if (isFirstDose)
        {
          isFirstDoseIsPeriodicOrWholePRNOrEoOrOneOff=true;
          isFirstDose = false;
        }
        continue;
      }
      final List<DIT> doseInstances =
        new ArrayList<DIT>(dd.getDoseInstances());
      Collections.sort(doseInstances, CommonToolkit.INSTANCE.getDoseInstanceComparator());
      final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X);
      for (final DITdoseInstance : doseInstances)
          {
    }
Answer 1

Look, you verify X two times and both times is using || operator.

If X is true then first condition will be met and loop will continue to next iteration.

It means that when you verify X at final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X); then it is always false because if it is true then execution cannot reach this point.

IDEA suggests you simplify to final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail));

Rent Charter Buses Company
READ ALSO
Why are URLs not resoliving in jsp view of intellij with struts 2 convention

Why are URLs not resoliving in jsp view of intellij with struts 2 convention

I have two "errors" with url references that appear when using struts forms in a new project I'm templating out in IntelliJ IdeaIt's the strangest thing because neither of them are actual errors

138
Absolute positions in PDFBox

Absolute positions in PDFBox

I'm writing a program that converts TeX-generated PDFs back to a TeX-like string of textIn order to achieve that I use Apache PDFBox

235
Recursively populate JTree, using list of list

Recursively populate JTree, using list of list

I want to implement a method optimization of process, I reduced this process simple (multiplication and division) like a Tree shown

179
How to show all the pages of a pdf instead of just one in pdf.js

How to show all the pages of a pdf instead of just one in pdf.js

I am having trouble showing all the pages of a PDF instead of one using pdfjs

174