Coverage on new lines when the only changes are cosmetic (whitespace/comments)

  • SonarQube 7.7 (build 23042)
  • SonarJava 5.13.1 (build 18282)
  • Git 1.9 (build 1725)

Analysis: SonarQube

Steps to reproduce:

From 5e92cd1bd5cfe73e1a29fcf45081c59b5e19deed Mon Sep 17 00:00:00 2001
From: Artem Bobko <artem.bobko@duallab.com>
Date: Wed, 28 Aug 2019 20:15:42 +0300
Subject: [PATCH] Fix inline comments in barcodes, forms and io

---
 .../com/itextpdf/barcodes/BarcodeEANSUPP.java |   3 +-
 .../com/itextpdf/barcodes/BarcodePostnet.java |  15 +-
 .../com/itextpdf/barcodes/qrcode/QRCode.java  |   3 +-
 .../itextpdf/forms/fields/PdfFormField.java   |   9 +-
 .../com/itextpdf/forms/xfdf/AnnotObject.java  |   4 +-
 .../forms/xfdf/XfdfObjectFactory.java         |   8 +-
 .../itextpdf/forms/xfdf/XfdfObjectUtils.java  |   3 +-
 .../forms/FormFieldFlatteningTest.java        |   9 +-
 .../com/itextpdf/forms/PdfFormFieldTest.java  |   6 +-
 .../java/com/itextpdf/io/codec/BitFile.java   |  23 +--
 .../com/itextpdf/io/font/FontEncoding.java    |   3 +-
 .../io/font/FontProgramDescriptorFactory.java |   6 +-
 .../itextpdf/io/font/FontProgramFactory.java  |   6 +-
 .../com/itextpdf/io/font/WoffConverter.java   |  24 ++--
 .../com/itextpdf/io/font/otf/GlyphLine.java   |   3 +-
 .../itextpdf/io/font/otf/GposLookupType4.java |   3 +-
 .../itextpdf/io/font/otf/GposLookupType5.java |   3 +-
 .../itextpdf/io/font/otf/GposLookupType6.java |   3 +-
 .../itextpdf/io/font/otf/GsubLookupType4.java |   3 +-
 .../itextpdf/io/font/otf/OpenTypeFeature.java |   3 +-
 .../io/font/otf/OpenTypeFontTableReader.java  |   4 +-
 .../io/font/otf/OpenTypeGdefTableReader.java  |   9 +-
 .../com/itextpdf/io/image/BmpImageHelper.java |   3 +-
 .../com/itextpdf/io/image/PngImageHelper.java |  13 +-
 .../source/ByteBufferRandomAccessSource.java  |   3 +-
 .../com/itextpdf/io/source/ByteUtils.java     |   6 +-
 .../com/itextpdf/io/source/PdfTokenizer.java  |   3 +-
 31 files changed, 342 insertions(+), 185 deletions(-)

diff --git a/barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEANSUPP.java b/barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEANSUPP.java
index 56df187db1..e5d1a465b4 100644
--- a/barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEANSUPP.java
+++ b/barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEANSUPP.java
@@ -70,7 +70,8 @@ public class BarcodeEANSUPP extends Barcode1D {
      */
     public BarcodeEANSUPP(Barcode1D ean, Barcode1D supp) {
         super(ean.document);
-        n = 8; // horizontal distance between the two barcodes
+        // horizontal distance between the two barcodes
+        n = 8;
         this.ean = ean;
         this.supp = supp;
     }
diff --git a/barcodes/src/main/java/com/itextpdf/barcodes/BarcodePostnet.java b/barcodes/src/main/java/com/itextpdf/barcodes/BarcodePostnet.java
index 63c49dfc8c..2c0c3697ba 100644
--- a/barcodes/src/main/java/com/itextpdf/barcodes/BarcodePostnet.java
+++ b/barcodes/src/main/java/com/itextpdf/barcodes/BarcodePostnet.java
@@ -75,11 +75,16 @@ public class BarcodePostnet extends Barcode1D {
 
     public BarcodePostnet(PdfDocument document) {
         super(document);
-        n = 72f / 22f; // distance between bars
-        x = 0.02f * 72f; // bar width
-        barHeight = 0.125f * 72f; // height of the tall bars
-        size = 0.05f * 72f; // height of the short bars
-        codeType = TYPE_POSTNET; // type of code
+        // distance between bars
+        n = 72f / 22f;
+        // bar width
+        x = 0.02f * 72f;
+        // height of the tall bars
+        barHeight = 0.125f * 72f;
+        // height of the short bars
+        size = 0.05f * 72f;
+        // type of code
+        codeType = TYPE_POSTNET;
     }
 
     /** Creates the bars for Postnet.
diff --git a/barcodes/src/main/java/com/itextpdf/barcodes/qrcode/QRCode.java b/barcodes/src/main/java/com/itextpdf/barcodes/qrcode/QRCode.java
index 64a91a00b5..2126a809d1 100644
--- a/barcodes/src/main/java/com/itextpdf/barcodes/qrcode/QRCode.java
+++ b/barcodes/src/main/java/com/itextpdf/barcodes/qrcode/QRCode.java
@@ -190,8 +190,9 @@ final class QRCode {
                         // ByteMatrix stuff.
                         matrix != null &&
                         matrixWidth == matrix.getWidth() &&
+                        // Must be square.
                         // See 7.3.1 of JISX0510:2004 (p.5).
-                        matrix.getWidth() == matrix.getHeight(); // Must be square.
+                        matrix.getWidth() == matrix.getHeight();
     }
 
     /**
diff --git a/forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java b/forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java
index fb1fcc75d5..2b6dc59a5f 100644
--- a/forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java
+++ b/forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java
@@ -2336,9 +2336,11 @@ public class PdfFormField extends PdfObjectWrapper<PdfDictionary> {
     }
 
     private String getRadioButtonValue(String value) {
-        assert value != null; //Otherwise something wrong with getValueAsString().
+        //Otherwise something wrong with getValueAsString().
+        assert value != null;
         if ("".equals(value)) {
-            value = "Yes"; //let it as default value
+            //let it as default value
+            value = "Yes";
             for (String state: getAppearanceStates()) {
                 if (!"Off".equals(state)) {
                     value = state;
@@ -3521,7 +3523,8 @@ public class PdfFormField extends PdfObjectWrapper<PdfDictionary> {
                 }
             }
         }
-        sb.deleteCharAt(sb.length() - 1); // last '\n'
+        // last '\n'
+        sb.deleteCharAt(sb.length() - 1);
         return sb.toString();
     }
 
diff --git a/forms/src/main/java/com/itextpdf/forms/xfdf/AnnotObject.java b/forms/src/main/java/com/itextpdf/forms/xfdf/AnnotObject.java
index c3f58a0dc2..b82458e4a1 100644
--- a/forms/src/main/java/com/itextpdf/forms/xfdf/AnnotObject.java
+++ b/forms/src/main/java/com/itextpdf/forms/xfdf/AnnotObject.java
@@ -77,7 +77,7 @@ public class AnnotObject {
      * Content model: text string.
      * For more details see paragraph 6.5.4 in Xfdf document specification.
      */
-    private PdfString contents;//basically text string
+    private PdfString contents;
 
     /**
      * Represents contents-richtext tag in Xfdf document structure. Is a child of caret, circle, fileattachment, freetext,
@@ -116,7 +116,7 @@ public class AnnotObject {
      * Content model: Base64 encoded string.
      * For more details see paragraph 6.5.1 in Xfdf document specification.
      */
-    private String appearance;//should be Base64String
+    private String appearance;
 
     /**
      * Represents the defaultappearance element, a child of the caret and freetext elements.
diff --git a/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectFactory.java b/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectFactory.java
index 6fd2755d15..5e32a63990 100644
--- a/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectFactory.java
+++ b/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectFactory.java
@@ -284,18 +284,20 @@ public class XfdfObjectFactory {
         for (int temp = 0; temp < children.getLength(); temp++) {
             Node node = children.item(temp);
             if (node.getNodeType() == Node.TEXT_NODE) {
-                annotObject.setContents(new PdfString(node.getNodeValue()));//getTextContent?
+                // getTextContent?
+                annotObject.setContents(new PdfString(node.getNodeValue()));
             }
         }
     }
 
     private void visitContentsRichTextSubelement(Node parentNode, AnnotObject annotObject) {
-        //no attributes, inside a text string or rich text string
+        // no attributes, inside a text string or rich text string
         NodeList children = parentNode.getChildNodes();
         for (int temp = 0; temp < children.getLength(); temp++) {
             Node node = children.item(temp);
             if (node.getNodeType() == Node.TEXT_NODE) {
-                annotObject.setContentsRichText(new PdfString(node.getNodeValue()));//getTextContent?
+                // getTextContent?
+                annotObject.setContentsRichText(new PdfString(node.getNodeValue()));
             }
         }
     }
diff --git a/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectUtils.java b/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectUtils.java
index 2414a41448..948181e2d4 100644
--- a/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectUtils.java
+++ b/forms/src/main/java/com/itextpdf/forms/xfdf/XfdfObjectUtils.java
@@ -164,7 +164,8 @@ final class XfdfObjectUtils {
 
         for(String flag : flagsList) {
             if (flagMap.containsKey(flag)) {
-                result += (int) flagMap.get(flag);//implicit cast  for autoporting
+                //implicit cast  for autoporting
+                result += (int) flagMap.get(flag);
             }
         }
         return result;
diff --git a/forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java b/forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java
index 63b11be770..e038315ea3 100644
--- a/forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java
+++ b/forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java
@@ -219,11 +219,14 @@ public class FormFieldFlatteningTest extends ExtendedITextTest {
 
                 Integer justification = field.getJustification();
                 if (null == justification || 0 == (int) justification) {
-                    field.setBackgroundColor(new DeviceRgb(255, 200, 200)); // reddish
+                    // reddish
+                    field.setBackgroundColor(new DeviceRgb(255, 200, 200));
                 } else if (1 == (int) justification) {
-                    field.setBackgroundColor(new DeviceRgb(200, 255, 200)); // greenish
+                    // greenish
+                    field.setBackgroundColor(new DeviceRgb(200, 255, 200));
                 } else if (2 == (int) justification) {
-                    field.setBackgroundColor(new DeviceRgb(200, 200, 255)); // blueish
+                    // blueish
+                    field.setBackgroundColor(new DeviceRgb(200, 200, 255));
                 }
 
                 field.setValue(newValue);
diff --git a/forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java b/forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java
index 2e0021fdcb..a92a278f32 100644
--- a/forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java
+++ b/forms/src/test/java/com/itextpdf/forms/PdfFormFieldTest.java
@@ -178,7 +178,8 @@ public class PdfFormFieldTest extends ExtendedITextTest {
         PdfDocument pdfDoc = new PdfDocument(new PdfReader(filename));
         PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
         Map<String, PdfFormField> formFields = form.getFormFields();
-        String fieldName = "\u5E10\u53F71"; // 帐号1: account number 1
+        // 帐号1: account number 1
+        String fieldName = "\u5E10\u53F71";
         Assert.assertEquals(fieldName, formFields.keySet().toArray(new String[1])[0]);
     }
 
@@ -187,7 +188,8 @@ public class PdfFormFieldTest extends ExtendedITextTest {
         String filename = sourceFolder + "unicodeFormFieldFile.pdf";
         PdfDocument pdfDoc = new PdfDocument(new PdfReader(filename));
         PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
-        String fieldName = "\u5E10\u53F71"; // 帐号1: account number 1
+        // 帐号1: account number 1
+        String fieldName = "\u5E10\u53F71";
         Assert.assertNotNull(form.getField(fieldName));
     }
 
diff --git a/io/src/main/java/com/itextpdf/io/codec/BitFile.java b/io/src/main/java/com/itextpdf/io/codec/BitFile.java
index 749c86e8e2..26436b6da6 100644
--- a/io/src/main/java/com/itextpdf/io/codec/BitFile.java
+++ b/io/src/main/java/com/itextpdf/io/codec/BitFile.java
@@ -93,7 +93,8 @@ class BitFile {
 
     public void writeBits(int bits, int numbits) throws IOException {
         int bitsWritten = 0;
-        int numBytes = 255;        // gif block count
+        // gif block count
+        int numBytes = 255;
         do {
             // This handles the GIF block count stuff
             if ((index == 254 && bitsLeft == 0) || index > 254) {
@@ -107,9 +108,11 @@ class BitFile {
                 bitsLeft = 8;
             }
 
-            if (numbits <= bitsLeft) // bits contents fit in current index byte
+            // bits contents fit in current index byte
+            if (numbits <= bitsLeft)
             {
-                if (blocks) // GIF
+                // GIF
+                if (blocks)
                 {
                     buffer[index] |= (byte) ((bits & ((1 << numbits) - 1)) << (8 - bitsLeft));
                     bitsWritten += numbits;
@@ -122,9 +125,11 @@ class BitFile {
                     numbits = 0;
 
                 }
-            } else // bits overflow from current byte to next.
-            {
-                if (blocks)    // GIF
+            } else {
+                // bits overflow from current byte to next.
+
+                // GIF
+                if (blocks)
                 {
                     // if bits  > space left in current byte then the lowest order bits
                     // of code are taken and put in current byte and rest put in next.
@@ -140,9 +145,11 @@ class BitFile {
                     // at highest order bit location !!
                     int topbits = (bits >>> (numbits - bitsLeft)) & ((1 << bitsLeft) - 1);
                     buffer[index] |= (byte) topbits;
-                    numbits -= bitsLeft;    // ok this many bits gone off the top
+                    // ok this many bits gone off the top
+                    numbits -= bitsLeft;
                     bitsWritten += bitsLeft;
-                    buffer[++index] = 0;    // next index
+                    // next index
+                    buffer[++index] = 0;
                     bitsLeft = 8;
                 }
             }
diff --git a/io/src/main/java/com/itextpdf/io/font/FontEncoding.java b/io/src/main/java/com/itextpdf/io/font/FontEncoding.java
index 556bd5f59b..769aff2b30 100644
--- a/io/src/main/java/com/itextpdf/io/font/FontEncoding.java
+++ b/io/src/main/java/com/itextpdf/io/font/FontEncoding.java
@@ -290,7 +290,8 @@ public class FontEncoding implements Serializable {
     }
 
     protected void fillNamedEncoding() {
-        PdfEncodings.convertToBytes(" ", baseEncoding); // check if the encoding exists
+        // check if the encoding exists
+        PdfEncodings.convertToBytes(" ", baseEncoding);
         boolean stdEncoding = PdfEncodings.WINANSI.equals(baseEncoding) || PdfEncodings.MACROMAN.equals(baseEncoding);
         if (!stdEncoding && differences == null) {
             differences = new String[256];
diff --git a/io/src/main/java/com/itextpdf/io/font/FontProgramDescriptorFactory.java b/io/src/main/java/com/itextpdf/io/font/FontProgramDescriptorFactory.java
index 1e15c15851..6b6988fa78 100644
--- a/io/src/main/java/com/itextpdf/io/font/FontProgramDescriptorFactory.java
+++ b/io/src/main/java/com/itextpdf/io/font/FontProgramDescriptorFactory.java
@@ -141,8 +141,10 @@ public final class FontProgramDescriptorFactory {
             String ttcName;
             int ttcIndex;
             try {
-                ttcName = baseName.substring(0, ttcSplit + 4); // count(.ttc) = 4
-                ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5)); // count(.ttc,) = 5)
+                // count(.ttc) = 4
+                ttcName = baseName.substring(0, ttcSplit + 4);
+                // count(.ttc,) = 5)
+                ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5));
             } catch (NumberFormatException nfe) {
                 throw new IOException(nfe.getMessage(), nfe);
             }
diff --git a/io/src/main/java/com/itextpdf/io/font/FontProgramFactory.java b/io/src/main/java/com/itextpdf/io/font/FontProgramFactory.java
index 6d8ee80796..501fb7489f 100644
--- a/io/src/main/java/com/itextpdf/io/font/FontProgramFactory.java
+++ b/io/src/main/java/com/itextpdf/io/font/FontProgramFactory.java
@@ -231,8 +231,10 @@ public final class FontProgramFactory {
                 int ttcSplit = baseName.toLowerCase().indexOf(".ttc,");
                 if (ttcSplit > 0) {
                     try {
-                        String ttcName = baseName.substring(0, ttcSplit + 4); // count(.ttc) = 4
-                        int ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5)); // count(.ttc,) = 5)
+                        // count(.ttc) = 4
+                        String ttcName = baseName.substring(0, ttcSplit + 4);
+                        // count(.ttc,) = 5)
+                        int ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5));
                         fontBuilt = new TrueTypeFont(ttcName, ttcIndex);
                     } catch (NumberFormatException nfe) {
                         throw new IOException(nfe.getMessage(), nfe);
diff --git a/io/src/main/java/com/itextpdf/io/font/WoffConverter.java b/io/src/main/java/com/itextpdf/io/font/WoffConverter.java
index 47709f8f22..34a3dadeb0 100644
--- a/io/src/main/java/com/itextpdf/io/font/WoffConverter.java
+++ b/io/src/main/java/com/itextpdf/io/font/WoffConverter.java
@@ -88,16 +88,24 @@ class WoffConverter {
         long totalSfntSize = bytesToUInt(woffBytes, srcPos);
         srcPos += 4;
 
-        srcPos += 2; // majorVersion
-        srcPos += 2; // minorVersion
-        srcPos += 4; // metaOffset
-        srcPos += 4; // metaLength
-        srcPos += 4; // metaOrigLength
-        srcPos += 4; // privOffset
-        srcPos += 4; // privLength
+        // majorVersion
+        srcPos += 2;
+        // minorVersion
+        srcPos += 2;
+        // metaOffset
+        srcPos += 4;
+        // metaLength
+        srcPos += 4;
+        // metaOrigLength
+        srcPos += 4;
+        // privOffset
+        srcPos += 4;
+        // privLength
+        srcPos += 4;
 
 
-        byte[] otfBytes = new byte[(int) totalSfntSize]; // assuming font won't be larger than 2GB
+        // assuming font won't be larger than 2GB
+        byte[] otfBytes = new byte[(int) totalSfntSize];
         System.arraycopy(flavor, 0, otfBytes, destPos, 4);
         destPos += 4;
         System.arraycopy(numTables, 0, otfBytes, destPos, 2);
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java b/io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java
index 23a3f0de6f..08a7176e34 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java
@@ -293,7 +293,8 @@ public class GlyphLine implements Serializable {
     }
 
     public void substituteOneToMany(OpenTypeFontTableReader tableReader, int[] substGlyphIds) {
-        int substCode = substGlyphIds[0]; //sequence length shall be at least 1
+        //sequence length shall be at least 1
+        int substCode = substGlyphIds[0];
         Glyph glyph = tableReader.getGlyph(substCode);
         glyphs.set(idx, glyph);
 
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType4.java b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType4.java
index 37102c865c..917a90f448 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType4.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType4.java
@@ -124,7 +124,8 @@ public class GposLookupType4 extends OpenTableLookup {
     protected void readSubTable(int subTableLocation) throws java.io.IOException {
         openReader.rf.seek(subTableLocation);
 
-        openReader.rf.readUnsignedShort(); //skip format, always 1
+        // skip format, always 1
+        openReader.rf.readUnsignedShort();
         int markCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int baseCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int classCount = openReader.rf.readUnsignedShort();
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType5.java b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType5.java
index aec6d2eae4..298982e196 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType5.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType5.java
@@ -126,7 +126,8 @@ public class GposLookupType5 extends OpenTableLookup {
     protected void readSubTable(int subTableLocation) throws java.io.IOException {
         openReader.rf.seek(subTableLocation);
 
-        openReader.rf.readUnsignedShort(); //skip format, always 1
+        // skip format, always 1
+        openReader.rf.readUnsignedShort();
         int markCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int ligatureCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int classCount = openReader.rf.readUnsignedShort();
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType6.java b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType6.java
index 1e210082ad..af9c53fe55 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType6.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/GposLookupType6.java
@@ -128,7 +128,8 @@ public class GposLookupType6 extends OpenTableLookup {
     protected void readSubTable(int subTableLocation) throws java.io.IOException {
         openReader.rf.seek(subTableLocation);
 
-        openReader.rf.readUnsignedShort(); //skip format, always 1
+        // skip format, always 1
+        openReader.rf.readUnsignedShort();
         int markCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int baseCoverageLocation = openReader.rf.readUnsignedShort() + subTableLocation;
         int classCount = openReader.rf.readUnsignedShort();
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/GsubLookupType4.java b/io/src/main/java/com/itextpdf/io/font/otf/GsubLookupType4.java
index 2acf98c3b7..b543081aed 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/GsubLookupType4.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/GsubLookupType4.java
@@ -104,7 +104,8 @@ public class GsubLookupType4 extends OpenTableLookup {
     @Override
     protected void readSubTable(int subTableLocation) throws java.io.IOException {
         openReader.rf.seek(subTableLocation);
-        openReader.rf.readShort(); //subformat - always 1
+        // subformat - always 1
+        openReader.rf.readShort();
         int coverage = openReader.rf.readUnsignedShort() + subTableLocation;
         int ligSetCount = openReader.rf.readUnsignedShort();
         int[] ligatureSet = new int[ligSetCount];
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFeature.java b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFeature.java
index d88e4f8180..fa7edb936d 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFeature.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFeature.java
@@ -58,7 +58,8 @@ public class OpenTypeFeature implements Serializable {
         openTypeReader.rf.seek(locationFeatureTable);
         TagAndLocation[] tagsLocs = openTypeReader.readTagAndLocations(locationFeatureTable);
         for (TagAndLocation tagLoc : tagsLocs) {
-            openTypeReader.rf.seek(tagLoc.location + 2); //+2 don't use FeatureParams
+            // +2 don't use FeatureParams
+            openTypeReader.rf.seek(tagLoc.location + 2L);
             int lookupCount = openTypeReader.rf.readUnsignedShort();
             FeatureRecord rec = new FeatureRecord();
             rec.tag = tagLoc.tag;
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java
index d0f889778f..e59d5c98f1 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeFontTableReader.java
@@ -233,7 +233,9 @@ public abstract class OpenTypeFontTableReader implements Serializable {
     final void startReadingTable() throws FontReadingException {
         try {
             rf.seek(tableLocation);
-            /*int version =*/ rf.readInt(); //version not used
+            /*int version =*/
+            // version not used
+            rf.readInt();
             int scriptListOffset = rf.readUnsignedShort();
             int featureListOffset = rf.readUnsignedShort();
             int lookupListOffset = rf.readUnsignedShort();
diff --git a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeGdefTableReader.java b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeGdefTableReader.java
index 02a301cfac..e3f82eed9f 100644
--- a/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeGdefTableReader.java
+++ b/io/src/main/java/com/itextpdf/io/font/otf/OpenTypeGdefTableReader.java
@@ -67,10 +67,13 @@ public class OpenTypeGdefTableReader implements Serializable{
     public void readTable() throws java.io.IOException {
         if (tableLocation > 0) {
             rf.seek(tableLocation);
-            rf.readUnsignedInt(); //version, we only support 0x00010000
+            // version, we only support 0x00010000
+            rf.readUnsignedInt();
             int glyphClassDefOffset = rf.readUnsignedShort();
-            rf.readUnsignedShort(); //skip Attachment Point List Table
-            rf.readUnsignedShort(); //skip Ligature Caret List Table
+            // skip Attachment Point List Table
+            rf.readUnsignedShort();
+            // skip Ligature Caret List Table
+            rf.readUnsignedShort();
             int markAttachClassDefOffset = rf.readUnsignedShort();
             if (glyphClassDefOffset > 0) {
                 glyphClass = OtfClass.create(rf, glyphClassDefOffset + tableLocation);
diff --git a/io/src/main/java/com/itextpdf/io/image/BmpImageHelper.java b/io/src/main/java/com/itextpdf/io/image/BmpImageHelper.java
index 273e0f6916..52d68e9676 100644
--- a/io/src/main/java/com/itextpdf/io/image/BmpImageHelper.java
+++ b/io/src/main/java/com/itextpdf/io/image/BmpImageHelper.java
@@ -552,7 +552,8 @@ final class BmpImageHelper {
     }
 
     private static boolean getImage(BmpParameters bmp) throws java.io.IOException {
-        byte bdata[]; // buffer for byte data
+        // buffer for byte data
+        byte[] bdata;
         //	if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
         //	    bdata = (byte[])((DataBufferByte)tile.getDataBuffer()).getData();
         //	else if (sampleModel.getDataType() == DataBuffer.TYPE_USHORT)
diff --git a/io/src/main/java/com/itextpdf/io/image/PngImageHelper.java b/io/src/main/java/com/itextpdf/io/image/PngImageHelper.java
index 730e43d9b9..cbdfb012ac 100644
--- a/io/src/main/java/com/itextpdf/io/image/PngImageHelper.java
+++ b/io/src/main/java/com/itextpdf/io/image/PngImageHelper.java
@@ -91,7 +91,8 @@ class PngImageHelper {
         int transGreen = -1;
         int transBlue = -1;
         int inputBands;
-        int bytesPerPixel; // number of bytes per input pixel
+        // number of bytes per input pixel
+        int bytesPerPixel;
         byte[] colorTable;
         float gamma = 1f;
         boolean hasCHRM = false;
@@ -329,7 +330,7 @@ class PngImageHelper {
                     float XC = YC * png.xB / png.yB;
                     float ZC = YC * ((1 - png.xB) / png.yB - 1);
                     float XW = XA + XB + XC;
-                    float YW = 1;//YA+YB+YC;
+                    float YW = 1;
                     float ZW = ZA + ZB + ZC;
                     float[] wpa = new float[3];
                     wpa[0] = XW;
@@ -679,10 +680,12 @@ class PngImageHelper {
                 dstX = xOffset;
                 for (srcX = 0; srcX < width; srcX++) {
                     int idx = outPixel[srcX];
-                    if (idx < png.trans.length)
+                    if (idx < png.trans.length) {
                         v[0] = png.trans[idx];
-                    else
-                        v[0] = 255; // Patrick Valsecchi
+                    } else {
+                        // Patrick Valsecchi
+                        v[0] = 255;
+                    }
                     setPixel(png.smask, v, 0, 1, dstX, y, 8, yStride);
                     dstX += step;
                 }
diff --git a/io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java b/io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java
index 7873b6a5bb..66be3002cd 100644
--- a/io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java
+++ b/io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java
@@ -102,7 +102,8 @@ class ByteBufferRandomAccessSource implements IRandomAccessSource, Serializable
             byte b = byteBuffer.get((int) position);
             return b & 0xff;
         } catch (BufferUnderflowException e) {
-            return -1; // EOF
+            // EOF
+            return -1;
         }
     }
 
diff --git a/io/src/main/java/com/itextpdf/io/source/ByteUtils.java b/io/src/main/java/com/itextpdf/io/source/ByteUtils.java
index c67a0978bb..d899b267bc 100644
--- a/io/src/main/java/com/itextpdf/io/source/ByteUtils.java
+++ b/io/src/main/java/com/itextpdf/io/source/ByteUtils.java
@@ -212,7 +212,8 @@ public final class ByteUtils {
             }
             int fracLen = 0;
             if (v % 100 != 0) {
-                fracLen = 2;                             //fracLen include '.'
+                //fracLen include '.'
+                fracLen = 2;
                 if (v % 10 != 0) {
                     fracLen++;
                 } else {
@@ -222,7 +223,8 @@ public final class ByteUtils {
                 v /= 100;
             }
             buf = buffer != null ? buffer : new ByteBuffer(intLen + fracLen + (negative ? 1 : 0));
-            for (int i = 0; i < fracLen - 1; i++) {     //-1 because fracLen include '.'
+            //-1 because fracLen include '.'
+            for (int i = 0; i < fracLen - 1; i++) {
                 buf.prepend(bytes[v % 10]);
                 v /= 10;
             }
diff --git a/io/src/main/java/com/itextpdf/io/source/PdfTokenizer.java b/io/src/main/java/com/itextpdf/io/source/PdfTokenizer.java
index 598cf9c68e..83bafc71fd 100644
--- a/io/src/main/java/com/itextpdf/io/source/PdfTokenizer.java
+++ b/io/src/main/java/com/itextpdf/io/source/PdfTokenizer.java
@@ -257,7 +257,8 @@ public class PdfTokenizer implements Closeable, Serializable {
             String str = readString(arrLength);
             int idx = str.lastIndexOf("startxref");
             if (idx >= 0) return pos + idx;
-            pos = pos - arrLength + 9;                  // 9 = "startxref".length()
+            // 9 = "startxref".length()
+            pos = pos - arrLength + 9;
         }
         throw new IOException(IOException.PdfStartxrefNotFound, this);
     }
-- 
2.20.1

  • Run an analysis

Actual result:

  • whitespace changes are detected as new lines to cover
  • comment changes are detected as new lines to cover
  • 119 lines detected as new code to cover
  • code coverage on new code is too low
  • Quality Gate fails

Expected result:

  • Only 2 lines (in OpenTypeFeature.java and BmpImageHelper.java) have new lines to cover.
  • Both lines are covered by tests, so there should be 100% coverage on new code.
  • For calculation of coverage on new code, SonarQube ignores changes to whitespace
  • For calculation of coverage on new code, SonarQube ignores changes to comments
  • Quality Gate passes

bump

I still haven’t found a solution. We now have to disable quality gates every time a developer edits a comment.

How do I contact SonarSource in a way that it is guaranteed to be read by a SonarSource employee and how much does that cost?

Hi,
Sorry for the very late reply.
Were the lines detected as “new lines” in SonarQube (highlighted with yellow background) matching what you see as modified code in GitHub?

Short answer: yes.
Longer answer: see above:

I can provide screenshots if you want, would that help?

Yes, a screenshot might help.
I’m trying to understand if the problem is that the detection of new lines is incorrect or if it is the test coverage that is inaccurate (or both).
If you are on Windows and the new spaces you see are at the end of the lines, it could be due to this problem that was fixed with the Git plugin v1.9.1.

Okay, here’s a screenshot.

Comment from the dev who made the screenshot:

Only whitespace changes - to be precise, the following replacement was made: ` (` → `(`

If this screenshot does not show you what you need to know, then please please please be very very very specific, because I am just an intermediate for our devs who reported this issue.

Our SonarQube instance runs on Debian Buster.

Thanks.
So all the lines highlighted with yellow background were changed and are considered to be new lines to cover. Isn’t that what you’d expect?
A change of a whitespace doesn’t change the fact that a line of code was changed, which should be covered. There is no distinction made at that level.
A line which is a comment on the other hand should not be considered as a line of code that should be covered.

Okay I will relay this to the dev team.

I haven’t got any feedback yet, but what I think they are trying to say is:

  • Sonarqube sees a difference with git diff.
  • Our dev team is only interested in differences with git diff --ignore-all-space (aka git diff -w).

It’s unreasonable to ignore spaces since the outcome of some rules might depend on those spaces.

I will also relay that to the dev team. Can you give me examples of such rules?

Let me ask the question in a different way. How do we fix what we see as a problem coming from SonarQube, without having to write tests to cover legacy code?

If legacy code is modified, it will be code included in the New Code Period, counting towards coverage on new code. There is no way around it.
If this was a big refactoring you did once, one option is to restart the New Code Period by changing its setting.

What we currently do, to bypass the quality gate when this happens, is to set the New Code Period to 1 day.

Hi @Amedee_Van_Gasse

If same 1000 LOC reads twice is it counting as 2000 LOC reads , or its counting only for new changes if exists

Best regards,
Randikam

Hi Randika,

I don’t understand. English is not my native language. Could you elaborate in Simple English?

Best regards,
Amedee