Examples of errors detected by the V6007 diagnostic


V6007. Expression is always true/false.


IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'i < endOffset' is always true. EnterAfterJavadocTagHandler.java 183


static Context parse(....) {
  ....
  for (int i = offset; i < endOffset; i++) {
    char c = text.charAt(i);
    if (c == '<' && i < endOffset && text.charAt(i + 1) == '/'
        && startTag != null
        && CharArrayUtil.regionMatches(text, i + 2, endOffset, startTag))
    {
      endTagStartOffset = i;
      break;
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-570] Expression 'i == exampleUsages.length' is always false. IntentionDescriptionPanel.java 192


private static void showUsages(....)
{
  ....
  for (int i = 0; i < exampleUsages.length; i++) {
    final TextDescriptor exampleUsage = exampleUsages[i];
    final String name = exampleUsage.getFileName();
    final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx();
    final String extension = fileTypeManager.getExtension(name);
    final FileType fileType = fileTypeManager.getFileTypeByExtension(extension);

    IntentionUsagePanel usagePanel;
    if (reuse) {
      usagePanel = (IntentionUsagePanel)panel.getComponent(i);
    }
    else {
      usagePanel = new IntentionUsagePanel();
      usagePanels.add(usagePanel);
    }
    usagePanel.reset(exampleUsage.getText(), fileType);

    if (!reuse) {
      if (i == exampleUsages.length) {                        // <=
        gb.gridwidth = GridBagConstraints.REMAINDER;
      }
      panel.add(usagePanel, gb);
      gb.gridx++;
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'buffer.length() > 0' is always true. DeleteUtil.java 62


public static String generateWarningMessage(....)
{
  ....
  if (buffer.length() > 0) {
    if (buffer.length() > 0) {
      buffer.append(" ").append(
        IdeBundle.message("prompt.delete.and")).append(" ");
    }
  }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-571] Expression 'index >= 0' is always true. Updater.java 184


public int findPreviousIndex(int current) {
  int count = myPainter.getErrorStripeCount();
  int foundIndex = -1;
  int foundLayer = 0;
  if (0 <= current && current < count) {
    current--;
    for (int index = count - 1; index >= 0; index++) {        // <=
      int layer = getLayer(index);
      if (layer > foundLayer) {
        foundIndex = index;
        foundLayer = layer;
      }
    }
  ....
}

IntelliJ IDEA Community Edition

V6007 [CWE-570] Expression '"0".equals(text)' is always false. ConvertIntegerToDecimalPredicate.java 46


public boolean satisfiedBy(@NotNull PsiElement element) {
  ....
  @NonNls final String text = expression.getText().replaceAll("_", "");
  if (text == null || text.length() < 2) {
    return false;
  }
  if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
    return false;
  }
  return text.charAt(0) == '0';
}

SpotBugs

V6007 [CWE-571] Expression 'count < 4' is always true. Util.java 394


public static String getXMLType(@WillNotClose InputStream in) throws IOException
{
  ....
  String s;
  int count = 0;
  while (count < 4) {
    s = r.readLine();
    if (s == null) {
      break;
    }
    Matcher m = tag.matcher(s);
    if (m.find()) {
      return m.group(1);
    }
  }
  throw new IOException("Didn't find xml tag");
  ....
}

SpotBugs

V6007 [CWE-570] Expression '"remove".equals(invokedMethodName)' is always false. FindUnrelatedTypesInGenericContainer.java 618


private void analyzeMethod(....) throws .... {
  ....
  if (invokedMethodName.startsWith("contains") ||
      "remove".equals(invokedMethodName)) {
  ....
  } else if ("get".equals(invokedMethodName) ||
             "remove".equals(invokedMethodName)) {
  ....
}

Bouncy Castle

V6007 [CWE-570] Expression 'c == '\r'' is always false. PEMUtil.java 38


private String readLine(InputStream in)
  throws IOException
{
  ....
  do
  {
    while (((c = in.read()) != '\r') && c != '\n' && (c >= 0))
    {
      if (c == '\r')
      {
        continue;
      }

      l.append((char)c);
    }
  }
  while (c >= 0 && l.length() == 0);
  ....
}

Bouncy Castle

V6007 [CWE-570] Expression '(b1 | b2) < 0' is always false. ArmoredInputStream.java 76


private static final byte[] decodingTable;

private int decode(
  int      in0,
  int      in1,
  int      in2,
  int      in3,
  int[]    out)
  throws IOException
{
  int    b1, b2, b3, b4;
  ....
  b1 = decodingTable[in0] & 0xff;
  b2 = decodingTable[in1] & 0xff;

  if ((b1 | b2) < 0)
  {
    throw new IOException("invalid armor");
  }
}

Bouncy Castle

V6007 [CWE-570] Expression 'j < numPassesKPG' is always false. McElieceKobaraImaiCipherTest.java 36


public void performTest()
  throws Exception
{
  int numPassesKPG = 0;   // TODO: this algorithm is broken
  int numPassesEncDec = 10;
  Random rand = new Random();
  byte[] mBytes;
  for (int j = 0; j < numPassesKPG; j++)
  ....
}


Bugs Found

Checked Projects
336
Collected Errors
12 745