From 0093da597f5c505a8b68cf6b2aeda4375821bf0e Mon Sep 17 00:00:00 2001 From: depryf Date: Tue, 23 Jul 2024 17:07:09 -0400 Subject: [PATCH] Fixed potential NPE --- build.gradle | 4 ++-- .../record/csv/CommaSeparatedLayoutTest.java | 8 +++---- .../record/fixed/FixedColumnsLayoutTest.java | 23 ++++++++++--------- .../record/fixed/naaccr/NaaccrLayoutTest.java | 8 +++---- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 8efaa23c..d5f33ffd 100644 --- a/build.gradle +++ b/build.gradle @@ -125,8 +125,8 @@ sonarqube { property "sonar.projectKey", "imsweb_layout" property "sonar.organization", "imsweb" property "sonar.host.url", "https://sonarcloud.io" - property 'sonar.exclusions', '**/lab/*' - property 'sonar.coverage.exclusions', '**/lab/*' + property "sonar.exclusions", "**/lab/**" + property "sonar.coverage.exclusions", "**/lab/**" } } diff --git a/src/test/java/com/imsweb/layout/record/csv/CommaSeparatedLayoutTest.java b/src/test/java/com/imsweb/layout/record/csv/CommaSeparatedLayoutTest.java index 310ef79f..27a83411 100644 --- a/src/test/java/com/imsweb/layout/record/csv/CommaSeparatedLayoutTest.java +++ b/src/test/java/com/imsweb/layout/record/csv/CommaSeparatedLayoutTest.java @@ -335,10 +335,10 @@ public String createLineFromRecord(Map rec, RecordLayoutOptions // read the data file using the new layout List> records = layout.readAllRecords(file); Assert.assertEquals(3, records.size()); - for (Map record : records) { - Assert.assertNotNull(record.get("recordType")); - Assert.assertNotNull(record.get("patientIdNumber")); - Assert.assertNotNull(record.get("race1")); + for (Map rec : records) { + Assert.assertNotNull(rec.get("recordType")); + Assert.assertNotNull(rec.get("patientIdNumber")); + Assert.assertNotNull(rec.get("race1")); } Assert.assertEquals("20100615", records.get(0).get("dateOfBirth")); Assert.assertEquals("2010", records.get(0).get("dateOfBirthYear")); diff --git a/src/test/java/com/imsweb/layout/record/fixed/FixedColumnsLayoutTest.java b/src/test/java/com/imsweb/layout/record/fixed/FixedColumnsLayoutTest.java index f56da1a5..37a265b5 100644 --- a/src/test/java/com/imsweb/layout/record/fixed/FixedColumnsLayoutTest.java +++ b/src/test/java/com/imsweb/layout/record/fixed/FixedColumnsLayoutTest.java @@ -23,6 +23,7 @@ import com.imsweb.layout.record.fixed.xml.FixedColumnLayoutXmlDto; import com.imsweb.seerutils.SeerUtils; +@SuppressWarnings("ALL") public class FixedColumnsLayoutTest { @Test @@ -342,29 +343,29 @@ public void testLayoutExtension() throws Exception { @Test public void testStateRequestorItems() throws IOException { - Map record = new HashMap<>(); - record.put("registryField1", "X"); + Map rec = new HashMap<>(); + rec.put("registryField1", "X"); // this layout defines a 1-char field at the beginning of the state requestor items RecordLayout layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-1.xml")); - String line = layout.createLineFromRecord(record, null); + String line = layout.createLineFromRecord(rec, null); Assert.assertEquals(3339, line.length()); - record = layout.createRecordFromLine(line, null, null); - Assert.assertEquals("X", record.get("registryField1")); + rec = layout.createRecordFromLine(line, null, null); + Assert.assertEquals("X", rec.get("registryField1")); // this layout defines a 1-char field in the middle of the state requestor items layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-2.xml")); - line = layout.createLineFromRecord(record, null); + line = layout.createLineFromRecord(rec, null); Assert.assertEquals(3339, line.length()); - record = layout.createRecordFromLine(line, null, null); - Assert.assertEquals("X", record.get("registryField1")); + rec = layout.createRecordFromLine(line, null, null); + Assert.assertEquals("X", rec.get("registryField1")); // this layout defines a 1-char field at the end of the state requestor items layout = new FixedColumnsLayout(Thread.currentThread().getContextClassLoader().getResource("testing-state-requestor-items-3.xml")); - line = layout.createLineFromRecord(record, null); + line = layout.createLineFromRecord(rec, null); Assert.assertEquals(3339, line.length()); - record = layout.createRecordFromLine(line, null, null); - Assert.assertEquals("X", record.get("registryField1")); + rec = layout.createRecordFromLine(line, null, null); + Assert.assertEquals("X", rec.get("registryField1")); } @Test diff --git a/src/test/java/com/imsweb/layout/record/fixed/naaccr/NaaccrLayoutTest.java b/src/test/java/com/imsweb/layout/record/fixed/naaccr/NaaccrLayoutTest.java index 4377baf2..8c09f45f 100644 --- a/src/test/java/com/imsweb/layout/record/fixed/naaccr/NaaccrLayoutTest.java +++ b/src/test/java/com/imsweb/layout/record/fixed/naaccr/NaaccrLayoutTest.java @@ -34,8 +34,8 @@ public void testDeprecationMappings() { public void testBuildFileInfo() throws IOException { RecordLayout layout = (RecordLayout)LayoutFactory.getLayout(LAYOUT_ID_NAACCR_16_INCIDENCE); - Map record = layout.readAllRecords(new File(TestingUtils.getWorkingDirectory() + "/src/test/resources/fake-naaccr16-1-rec.txt")).get(0); - StringBuilder buf = new StringBuilder(layout.createLineFromRecord(record, null)); + Map rec = layout.readAllRecords(new File(TestingUtils.getWorkingDirectory() + "/src/test/resources/fake-naaccr16-1-rec.txt")).get(0); + StringBuilder buf = new StringBuilder(layout.createLineFromRecord(rec, null)); String line = buf.toString(); String lineShort = line.substring(0, 25); @@ -143,12 +143,12 @@ public void testBuildFileInfo() throws IOException { buf.replace(0, 1, "A"); buf.replace(16, 19, "160"); Assert.assertNull(layout.buildFileInfo(buf.toString(), options)); - Assert.assertNull(layout.buildFileInfo(buf.toString().substring(0, 25), options)); + Assert.assertNull(layout.buildFileInfo(buf.substring(0, 25), options)); // wrong version buf.replace(0, 1, "I"); buf.replace(16, 19, "150"); Assert.assertNull(layout.buildFileInfo(buf.toString(), options)); - Assert.assertNull(layout.buildFileInfo(buf.toString().substring(0, 25), options)); + Assert.assertNull(layout.buildFileInfo(buf.substring(0, 25), options)); } }