From bd778ca76342b75722fc5a744b42c963ede0cebe Mon Sep 17 00:00:00 2001 From: Gilles Querret Date: Tue, 8 Oct 2024 11:04:58 +0200 Subject: [PATCH 1/4] Prepare 2.28.3 --- coverage-report/pom.xml | 16 ++++++++-------- database-parser/pom.xml | 2 +- listing-parser/pom.xml | 2 +- openedge-checks/pom.xml | 6 +++--- openedge-plugin/pom.xml | 8 ++++---- pom.xml | 2 +- profiler-parser/pom.xml | 2 +- proparse/pom.xml | 4 ++-- rcode-reader/pom.xml | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/coverage-report/pom.xml b/coverage-report/pom.xml index bb5bd6cd3..3a5b513aa 100644 --- a/coverage-report/pom.xml +++ b/coverage-report/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers coverage-report @@ -21,37 +21,37 @@ eu.rssw.openedge.rcode rcode-reader - 2.28.2 + 2.28.3 eu.rssw.sonar.openedge sonar-openedge-plugin - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers proparse - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers profiler-parser - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers database-parser - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers listing-parser - 2.28.2 + 2.28.3 eu.rssw.openedge.checks openedge-checks - 2.28.2 + 2.28.3 diff --git a/database-parser/pom.xml b/database-parser/pom.xml index 04d3b0c29..914bd3808 100644 --- a/database-parser/pom.xml +++ b/database-parser/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers database-parser diff --git a/listing-parser/pom.xml b/listing-parser/pom.xml index 75190d307..64258a6e5 100644 --- a/listing-parser/pom.xml +++ b/listing-parser/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers listing-parser diff --git a/openedge-checks/pom.xml b/openedge-checks/pom.xml index 3ab2370f3..2f1ab72cf 100644 --- a/openedge-checks/pom.xml +++ b/openedge-checks/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.checks openedge-checks @@ -23,12 +23,12 @@ eu.rssw.openedge.parsers database-parser - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers proparse - 2.28.2 + 2.28.3 org.testng diff --git a/openedge-plugin/pom.xml b/openedge-plugin/pom.xml index b585e7bcf..68859a354 100644 --- a/openedge-plugin/pom.xml +++ b/openedge-plugin/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.sonar.openedge sonar-openedge-plugin @@ -30,17 +30,17 @@ eu.rssw.openedge.checks openedge-checks - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers listing-parser - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers profiler-parser - 2.28.2 + 2.28.3 commons-io diff --git a/pom.xml b/pom.xml index 2797f5aa0..22aaeb210 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 pom OpenEdge plugin for SonarQube diff --git a/profiler-parser/pom.xml b/profiler-parser/pom.xml index 796081bc0..fc72b1391 100644 --- a/profiler-parser/pom.xml +++ b/profiler-parser/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers profiler-parser diff --git a/proparse/pom.xml b/proparse/pom.xml index 52392f9a5..a9f38f3be 100644 --- a/proparse/pom.xml +++ b/proparse/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.parsers proparse @@ -22,7 +22,7 @@ eu.rssw.openedge.rcode rcode-reader - 2.28.2 + 2.28.3 org.antlr diff --git a/rcode-reader/pom.xml b/rcode-reader/pom.xml index 6229e9119..6488869f6 100644 --- a/rcode-reader/pom.xml +++ b/rcode-reader/pom.xml @@ -5,7 +5,7 @@ eu.rssw sonar-openedge - 2.28.2 + 2.28.3 eu.rssw.openedge.rcode rcode-reader From d0eebb0f0a319c203c20987049932c27d358fd86 Mon Sep 17 00:00:00 2001 From: Gilles Querret Date: Fri, 4 Oct 2024 08:26:56 +0200 Subject: [PATCH 2/4] Remove dependency on commons-io In order to prevent pointless security issues from being reported against this library. --- openedge-plugin/pom.xml | 5 -- .../openedge/foundation/FilenameUtils.java | 85 +++++++++++++++++++ .../openedge/foundation/OpenEdgeSettings.java | 8 +- .../openedge/sensor/OpenEdgeSensor.java | 2 +- .../foundation/FilenameUtilsTest.java | 51 +++++++++++ proparse/pom.xml | 6 -- .../prorefactor/core/TreeParser04Test.java | 6 +- 7 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/FilenameUtils.java create mode 100644 openedge-plugin/src/test/java/org/sonar/plugins/openedge/foundation/FilenameUtilsTest.java diff --git a/openedge-plugin/pom.xml b/openedge-plugin/pom.xml index 68859a354..93853cad7 100644 --- a/openedge-plugin/pom.xml +++ b/openedge-plugin/pom.xml @@ -42,11 +42,6 @@ profiler-parser 2.28.3 - - commons-io - commons-io - 2.11.0 - org.sonarsource.sonarqube sonar-ws diff --git a/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/FilenameUtils.java b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/FilenameUtils.java new file mode 100644 index 000000000..112668c2e --- /dev/null +++ b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/FilenameUtils.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sonar.plugins.openedge.foundation; + +import static java.util.Objects.requireNonNull; + +/** + * Imported from commons-io + */ +public class FilenameUtils { + + private static final int NOT_FOUND = -1; + + private static final char EXTENSION_SEPARATOR = '.'; + /** + * The Unix separator character. + */ + private static final char UNIX_SEPARATOR = '/'; + + /** + * The Windows separator character. + */ + private static final char WINDOWS_SEPARATOR = '\\'; + + private FilenameUtils() { + // Only static methods here + } + + public static String getExtension(String filename) { + requireNonNull(filename); + final int index = indexOfExtension(filename); + if (index == NOT_FOUND) { + return ""; + } else { + return filename.substring(index + 1); + } + } + + public static String removeExtension(final String fileName) { + requireNonNull(fileName); + + final int index = indexOfExtension(fileName); + if (index == NOT_FOUND) { + return fileName; + } + return fileName.substring(0, index); + } + + public static String getBaseName(final String fileName) { + return removeExtension(getName(fileName)); + } + + public static String getName(final String fileName) { + if (fileName == null) { + return null; + } + return fileName.substring(indexOfLastSeparator(fileName) + 1); + } + + private static int indexOfExtension(String filename) { + final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); + final int lastSeparator = indexOfLastSeparator(filename); + return lastSeparator > extensionPos ? NOT_FOUND : extensionPos; + } + + private static int indexOfLastSeparator(String filename) { + final int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR); + final int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR); + return Math.max(lastUnixPos, lastWindowsPos); + } +} \ No newline at end of file diff --git a/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/OpenEdgeSettings.java b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/OpenEdgeSettings.java index 1ca2b3230..03f8668f1 100644 --- a/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/OpenEdgeSettings.java +++ b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/foundation/OpenEdgeSettings.java @@ -50,8 +50,6 @@ import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; import org.prorefactor.core.schema.IDatabase; import org.prorefactor.core.schema.Schema; import org.prorefactor.proparse.classdoc.ClassDocumentation; @@ -916,7 +914,11 @@ private Collection readSchemaFromProp1(String dbList) { desc = DatabaseDescription.deserialize(is, dbName); } catch (IOException caught) { LOG.error("Unable to deserialize from '" + serFile + "', deleting file", caught); - FileUtils.deleteQuietly(serFile); + try { + java.nio.file.Files.delete(serFile.toPath()); + } catch (IOException uncaught) { + // Nothing + } } } else { try { diff --git a/openedge-plugin/src/main/java/org/sonar/plugins/openedge/sensor/OpenEdgeSensor.java b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/sensor/OpenEdgeSensor.java index 67eff40d6..9789a58aa 100644 --- a/openedge-plugin/src/main/java/org/sonar/plugins/openedge/sensor/OpenEdgeSensor.java +++ b/openedge-plugin/src/main/java/org/sonar/plugins/openedge/sensor/OpenEdgeSensor.java @@ -19,7 +19,6 @@ */ package org.sonar.plugins.openedge.sensor; -import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.SonarProduct; @@ -31,6 +30,7 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.plugins.openedge.api.Constants; +import org.sonar.plugins.openedge.foundation.FilenameUtils; import org.sonar.plugins.openedge.foundation.OpenEdgeMetrics; public class OpenEdgeSensor implements Sensor { diff --git a/openedge-plugin/src/test/java/org/sonar/plugins/openedge/foundation/FilenameUtilsTest.java b/openedge-plugin/src/test/java/org/sonar/plugins/openedge/foundation/FilenameUtilsTest.java new file mode 100644 index 000000000..eea5b4758 --- /dev/null +++ b/openedge-plugin/src/test/java/org/sonar/plugins/openedge/foundation/FilenameUtilsTest.java @@ -0,0 +1,51 @@ +package org.sonar.plugins.openedge.foundation; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.expectThrows; +import static org.sonar.plugins.openedge.foundation.FilenameUtils.getExtension; +import static org.sonar.plugins.openedge.foundation.FilenameUtils.removeExtension; +import static org.sonar.plugins.openedge.foundation.FilenameUtils.getBaseName; +import static org.sonar.plugins.openedge.foundation.FilenameUtils.getName; + +import org.testng.annotations.Test; + +public class FilenameUtilsTest { + + @Test + public void testGetExtension() { + assertEquals(getExtension("C:\\foo\\bar\\filename.txt"), "txt"); + assertEquals(getExtension("filename.txt"), "txt"); + assertEquals(getExtension("filename.t"), "t"); + assertEquals(getExtension("filename"), ""); + assertEquals(getExtension("foo.bar\\filename"), ""); + expectThrows(NullPointerException.class, () -> getExtension(null)); + } + + @Test + public void testRemoveExtension() { + assertEquals(removeExtension("C:\\foo\\bar\\filename.txt"), "C:\\foo\\bar\\filename"); + assertEquals(removeExtension("filename.txt"), "filename"); + assertEquals(removeExtension("filename.t"), "filename"); + assertEquals(removeExtension("filename"), "filename"); + expectThrows(NullPointerException.class, () -> removeExtension(null)); + } + + @Test + public void testGetBaseName() { + assertEquals(getBaseName("C:\\foo\\bar\\filename.txt"), "filename"); + assertEquals(getBaseName("filename.txt"), "filename"); + assertEquals(getBaseName("filename.t"), "filename"); + assertEquals(getBaseName("filename"), "filename"); + expectThrows(NullPointerException.class, () -> getBaseName(null)); + } + + @Test + public void testGetName() { + assertEquals(getName("C:\\foo\\bar\\filename.txt"), "filename.txt"); + assertEquals(getName("filename.txt"), "filename.txt"); + assertEquals(getName("filename.t"), "filename.t"); + assertEquals(getName("filename"), "filename"); + assertEquals(getName(null), null); + } + +} diff --git a/proparse/pom.xml b/proparse/pom.xml index a9f38f3be..7c3ed7bce 100644 --- a/proparse/pom.xml +++ b/proparse/pom.xml @@ -82,12 +82,6 @@ 1.7.36 test - - commons-io - commons-io - 2.11.0 - test - diff --git a/proparse/src/test/java/org/prorefactor/core/TreeParser04Test.java b/proparse/src/test/java/org/prorefactor/core/TreeParser04Test.java index 57e445ab8..f3d67fe5d 100644 --- a/proparse/src/test/java/org/prorefactor/core/TreeParser04Test.java +++ b/proparse/src/test/java/org/prorefactor/core/TreeParser04Test.java @@ -15,15 +15,15 @@ ********************************************************************************/ package org.prorefactor.core; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.nio.file.Files; -import org.apache.commons.io.FileUtils; import org.prorefactor.core.util.SportsSchema; import org.prorefactor.core.util.TP01FramesTreeLister; import org.prorefactor.core.util.UnitTestProparseSettings; @@ -56,7 +56,7 @@ public void test01() throws IOException { nodeLister.print(' '); writer.close(); - assertTrue(FileUtils.contentEquals(new File(expectName), outFile)); + assertEquals(Files.readAllBytes(new File(expectName).toPath()), Files.readAllBytes(outFile.toPath())); } } From 2a6fdd649f8aefdab557cfafe0cd5ab3781dc15f Mon Sep 17 00:00:00 2001 From: Gilles Querret Date: Tue, 8 Oct 2024 11:07:03 +0200 Subject: [PATCH 3/4] Fix NPE in TreeParser01 --- proparse/src/main/java/org/prorefactor/treeparser/Block.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proparse/src/main/java/org/prorefactor/treeparser/Block.java b/proparse/src/main/java/org/prorefactor/treeparser/Block.java index 8b63ace1b..ec2f5e7b4 100644 --- a/proparse/src/main/java/org/prorefactor/treeparser/Block.java +++ b/proparse/src/main/java/org/prorefactor/treeparser/Block.java @@ -91,7 +91,8 @@ public void addBufferScopeReferences(BufferScope bufferScope) { // References do not get added to DO blocks. if (blockStatementNode.getNodeType() != ABLNodeType.DO) bufferScopes.add(bufferScope); - if (parentScopeBlock != null && bufferScope.getSymbol().getScope().getRootBlock() != this) { + if ((parentScopeBlock != null) && (bufferScope.getSymbol() != null) + && bufferScope.getSymbol().getScope().getRootBlock() != this) { parentScopeBlock.addBufferScopeReferences(bufferScope); } } From 09cac9c2903f09ed3d45d10560a85ca3e0d2fd3c Mon Sep 17 00:00:00 2001 From: Gilles Querret Date: Tue, 8 Oct 2024 11:08:11 +0200 Subject: [PATCH 4/4] Wrap IndexOutOfBoundsException in InvalidRCodeException when parsing rcode --- .../src/main/java/eu/rssw/pct/RCodeInfo.java | 85 +++++++++--------- .../pct/elements/fixed/TypeInfoKryoProxy.java | 3 + .../test/java/eu/rssw/pct/RCodeInfoTest.java | 12 +++ .../src/test/resources/rcode/Invalid.r | Bin 0 -> 150 bytes 4 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 rcode-reader/src/test/resources/rcode/Invalid.r diff --git a/rcode-reader/src/main/java/eu/rssw/pct/RCodeInfo.java b/rcode-reader/src/main/java/eu/rssw/pct/RCodeInfo.java index 1e5dc8a61..cce7e4d7f 100644 --- a/rcode-reader/src/main/java/eu/rssw/pct/RCodeInfo.java +++ b/rcode-reader/src/main/java/eu/rssw/pct/RCodeInfo.java @@ -115,50 +115,55 @@ public RCodeInfo(InputStream input) throws InvalidRCodeException, IOException { * @throws IOException */ public RCodeInfo(InputStream input, PrintStream out) throws InvalidRCodeException, IOException { - processHeader(input, out); - processSignatureBlock(input, out); - processSegmentTable(input, out); - byte[] rcodeBlock = readNBytes(input, rcodeSize); - - if ((version & 0x3FFF) >= 1200) { - crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V12, Short.BYTES).order(order).getShort() & 0xFFFF; - digest = Base64.getEncoder().encodeToString( - Arrays.copyOfRange(rcodeBlock, digestOffset + 16, digestOffset + 16 + 32)); - } else if ((version & 0x3FFF) >= 1100) { - crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V11, Short.BYTES).order(order).getShort() & 0xFFFF; - if (digestOffset > 0) - digest = bufferToHex(Arrays.copyOfRange(rcodeBlock, digestOffset, digestOffset + 16)); - } else { - crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V10, Short.BYTES).order(order).getShort() & 0xFFFF; - if (digestOffset > 0) - digest = bufferToHex(Arrays.copyOfRange(rcodeBlock, digestOffset, digestOffset + 16)); - } - - if ((version & 0x3FFF) >= 1100) { - if ((initialValueSegmentOffset >= 0) && (initialValueSegmentSize > 0)) { - processInitialValueSegment(Arrays.copyOfRange(rcodeBlock, initialValueSegmentOffset, - initialValueSegmentOffset + initialValueSegmentSize), out); - } - if ((actionSegmentOffset >= 0) && (actionSegmentSize > 0)) { - processActionSegment( - Arrays.copyOfRange(rcodeBlock, actionSegmentOffset, actionSegmentOffset + actionSegmentSize), out); + try { + processHeader(input, out); + processSignatureBlock(input, out); + processSegmentTable(input, out); + byte[] rcodeBlock = readNBytes(input, rcodeSize); + + if ((version & 0x3FFF) >= 1200) { + crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V12, Short.BYTES).order(order).getShort() & 0xFFFF; + digest = Base64.getEncoder().encodeToString( + Arrays.copyOfRange(rcodeBlock, digestOffset + 16, digestOffset + 16 + 32)); + } else if ((version & 0x3FFF) >= 1100) { + crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V11, Short.BYTES).order(order).getShort() & 0xFFFF; + if (digestOffset > 0) + digest = bufferToHex(Arrays.copyOfRange(rcodeBlock, digestOffset, digestOffset + 16)); + } else { + crc = ByteBuffer.wrap(rcodeBlock, IVS_CRC_OFFSET_V10, Short.BYTES).order(order).getShort() & 0xFFFF; + if (digestOffset > 0) + digest = bufferToHex(Arrays.copyOfRange(rcodeBlock, digestOffset, digestOffset + 16)); } - if ((ecodeSegmentOffset >= 0) && (ecodeSegmentSize > 0)) { - processEcodeSegment(Arrays.copyOfRange(rcodeBlock, ecodeSegmentOffset, ecodeSegmentOffset + ecodeSegmentSize), - out); + + if ((version & 0x3FFF) >= 1100) { + if ((initialValueSegmentOffset >= 0) && (initialValueSegmentSize > 0)) { + processInitialValueSegment(Arrays.copyOfRange(rcodeBlock, initialValueSegmentOffset, + initialValueSegmentOffset + initialValueSegmentSize), out); + } + if ((actionSegmentOffset >= 0) && (actionSegmentSize > 0)) { + processActionSegment( + Arrays.copyOfRange(rcodeBlock, actionSegmentOffset, actionSegmentOffset + actionSegmentSize), out); + } + if ((ecodeSegmentOffset >= 0) && (ecodeSegmentSize > 0)) { + processEcodeSegment(Arrays.copyOfRange(rcodeBlock, ecodeSegmentOffset, ecodeSegmentOffset + ecodeSegmentSize), + out); + } + if ((debugSegmentOffset > 0) && (debugSegmentSize > 0)) { + processDebugSegment(Arrays.copyOfRange(rcodeBlock, debugSegmentOffset, debugSegmentOffset + debugSegmentSize), + out); + } } - if ((debugSegmentOffset > 0) && (debugSegmentSize > 0)) { - processDebugSegment(Arrays.copyOfRange(rcodeBlock, debugSegmentOffset, debugSegmentOffset + debugSegmentSize), - out); + + if (typeBlockSize > 0) { + processTypeBlock(readNBytes(input, typeBlockSize), out); + isClass = true; } + + input.close(); + } catch (IndexOutOfBoundsException caught) { + // Prevent RuntimeException from bubbling up + throw new InvalidRCodeException(caught); } - - if (typeBlockSize > 0) { - processTypeBlock(readNBytes(input, typeBlockSize), out); - isClass = true; - } - - input.close(); } private final void processHeader(InputStream input, PrintStream out) throws IOException, InvalidRCodeException { diff --git a/rcode-reader/src/main/java/eu/rssw/pct/elements/fixed/TypeInfoKryoProxy.java b/rcode-reader/src/main/java/eu/rssw/pct/elements/fixed/TypeInfoKryoProxy.java index 2bd4dfd6c..1c75184f2 100644 --- a/rcode-reader/src/main/java/eu/rssw/pct/elements/fixed/TypeInfoKryoProxy.java +++ b/rcode-reader/src/main/java/eu/rssw/pct/elements/fixed/TypeInfoKryoProxy.java @@ -46,6 +46,9 @@ synchronized void checkTypeInfo() { try { typeInfo = (ITypeInfo) kryo.readClassAndObject(new Input(Files.readAllBytes(path))); } catch (IOException caught) { + typeInfo = new TypeInfo(typeName, false, false, BuiltinClasses.PLO_CLASSNAME, ""); + } catch (Throwable caught) { + typeInfo = new TypeInfo(typeName, false, false, BuiltinClasses.PLO_CLASSNAME, ""); } } diff --git a/rcode-reader/src/test/java/eu/rssw/pct/RCodeInfoTest.java b/rcode-reader/src/test/java/eu/rssw/pct/RCodeInfoTest.java index a32a6d9a0..734a1ab60 100644 --- a/rcode-reader/src/test/java/eu/rssw/pct/RCodeInfoTest.java +++ b/rcode-reader/src/test/java/eu/rssw/pct/RCodeInfoTest.java @@ -24,6 +24,7 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.io.FileInputStream; import java.io.IOException; @@ -74,6 +75,17 @@ public void init() throws IOException { } } + @Test + public void testInvalidRCode() throws IOException { + try (InputStream input = Files.newInputStream(Paths.get("src/test/resources/rcode/Invalid.r"))) { + new RCodeInfo(input); + fail("Invalid rcode, should have failed"); + } catch (InvalidRCodeException caught) { + if (!(caught.getCause() instanceof IndexOutOfBoundsException)) + fail("Invalid rcode, expected IOOBException wrapped in InvalidRCodeException"); + } + } + @Test public void testV10() throws IOException { try (InputStream input = Files.newInputStream(Paths.get("src/test/resources/rcode/simpleV10.r"))) { diff --git a/rcode-reader/src/test/resources/rcode/Invalid.r b/rcode-reader/src/test/resources/rcode/Invalid.r new file mode 100644 index 0000000000000000000000000000000000000000..8bf7fa42433a0e5cdefd5455fc7766ef4524cac9 GIT binary patch literal 150 zcmd