IllegalArgumentException when scanning Cobol sources

When scanning Acucobol sources we get the following exception:

ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: Line 31 is out of range for file C/IO/MEOPRHDR. File has 30 lines.
	at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43)
	at org.sonar.scanner.DefaultFileLinesContext.checkLineRange(DefaultFileLinesContext.java:63)
	at org.sonar.scanner.DefaultFileLinesContext.setIntValue(DefaultFileLinesContext.java:56)
	at com.sonarsource.cobol.plugin.squid.G.B(Unknown Source)
	at java.base/java.util.BitSet$1BitSetSpliterator.forEachRemaining(BitSet.java:1308)
	at java.base/java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:617)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at java.base/java.util.HashMap$Values.forEach(HashMap.java:1065)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at com.sonarsource.cobol.plugin.squid.G.execute(Unknown Source)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Apart from the Exception, the line count in the message is one-off: The file contains 29 lines, not 30.
We have seen that this happens when a sourcefile becomes smaller, and we can ‘fix’ it by adding (empty) lines to the end of the file.
But that is a very bad solution.
I have browsed the web to find a solution, but all I found is references to JaCoCo xml files that one would have to remove.
As we are scanning Cobol, I don’t think these answers are relevant to us.

We are using the following versions:

Cobol: Acucobol 10.2.1
SonarQube: * 10.2.1 (build 78527)
SonarScanner 5.0.1.3006

We would highly appreciate that this issue be fixed quickly, as it makes SonarQube useless for us now.

Hey @Jos_Abrahams

Can you widen the scope of the logs you’re sharing a little? I want to be sure which sensor is throwing the error.

Hi Colin,

Thanks for your quick reply!

I can share the whole pipeline log:

e[0KRunning with gitlab-runner 16.4.0 (4e724e03)e[0;m
e[0K  on gitlab03-runner12.build.pp-dev.nl JfS_x95k8, system ID: s_5a30057b959ee[0;m
section_start:1699876239:prepare_executor
e[0Ke[0Ke[36;1mPreparing the "shell" executore[0;me[0;m
e[0KUsing Shell (bash) executor...e[0;m
section_end:1699876239:prepare_executor
e[0Ksection_start:1699876239:prepare_script
e[0Ke[0Ke[36;1mPreparing environmente[0;me[0;m
Running on gitlab03-runner12.build.pp-dev.nl...
section_end:1699876240:prepare_script
e[0Ksection_start:1699876240:get_sources
e[0Ke[0Ke[36;1mGetting source from Git repositorye[0;me[0;m
e[32;1mFetching changes with git depth set to 50...e[0;m
Reinitialized existing Git repository in /build/builds/JfS_x95k8/0/cobol/sonar-cobol/.git/
e[32;1mChecking out 932af234 as detached HEAD (ref is master)...e[0;m
Removing cobol-src/
e[32;1mSkipping Git submodules setupe[0;m
section_end:1699876241:get_sources
e[0Ksection_start:1699876241:restore_cache
e[0Ke[0Ke[36;1mRestoring cachee[0;me[0;m
e[32;1mChecking cache for cobol-master-7-protected...e[0;m
Runtime platform                                  e[0;m  arche[0;m=amd64 ose[0;m=linux pide[0;m=124259 revisione[0;m=4e724e03 versione[0;m=16.4.0
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.e[0;m 
e[32;1mSuccessfully extracted cachee[0;m
section_end:1699876246:restore_cache
e[0Ksection_start:1699876246:step_script
e[0Ke[0Ke[36;1mExecuting "step_script" stage of the job scripte[0;me[0;m
e[32;1m$ export JAVA_HOME=$JAVA_17_HOMEe[0;m
e[32;1m$ export SONAR_SCANNER_OPTS="-Xmx1024m"e[0;m
e[32;1m$ $SONAR_EXE -Dsonar.host.url=$SONAR_HOST -Dproject.settings=$SONAR_PROJECT_PROPS -Dsonar.projectBaseDir=$COBOL_SRC_LOC/source/ -Dsonar.verbose=falsee[0;m
INFO: Scanner configuration file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-sonar.properties
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.8 Red Hat, Inc. (64-bit)
INFO: Linux 5.14.0-284.30.1.el9_2.x86_64 amd64
INFO: SONAR_SCANNER_OPTS=-Xmx1024m
INFO: User cache: /build/.sonar/cache
INFO: Analyzing on SonarQube server 10.2.1.78527
INFO: Default locale: "en_US", source code encoding: "CP850"
INFO: Load global settings
INFO: Load global settings (done) | time=128ms
INFO: Server id: AE6A090B-AYnPAHJ6DitoVKgH40Oy
INFO: User cache: /build/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=41ms
INFO: Load/download plugins (done) | time=250ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Process project properties (done) | time=8ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: JHP:COBOL
INFO: Base dir: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source
INFO: Working dir: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/.scannerwork
INFO: Load project settings for component key: 'JHP:COBOL'
INFO: Load project settings for component key: 'JHP:COBOL' (done) | time=21ms
INFO: Load project branches
INFO: Load project branches (done) | time=16ms
INFO: Load branch configuration
INFO: Detected branch/PR in 'GitLab'
INFO: Auto-configuring branch 'master'
INFO: Load branch configuration (done) | time=3ms
INFO: Auto-configuring with CI 'Gitlab CI'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=60ms
INFO: Load active rules
INFO: Load active rules (done) | time=2257ms
INFO: Load analysis cache
INFO: Load analysis cache | time=5130ms
INFO: Branch name: master
INFO: Load project repositories
INFO: Load project repositories (done) | time=212ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/ALFRED, **/*.test.ts, **/*.spec.ts
INFO:   Included tests: **/*.test.ts, **/*.spec.ts
INFO:   Excluded sources for coverage: **/main.ts, **/polyfills.ts, **/environments/environment*.ts, **/*module.ts, **/setupJest.ts, **/*
INFO:   Excluded sources for duplication: **/*
INFO: 16530 files indexed
INFO: 1 file ignored because of inclusion/exclusion patterns
INFO: Quality profile for cobol: PharmaPartners
INFO: ------------- Run sensors on module JHP:COBOL
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=21ms
INFO: Sensor CobolSquidSensor [cobol]
INFO: About to analyse COBOL Programs using 'microfocus-acucobol-gt-cobol' dialect and 'fixed' source code format.
INFO: Loading cache from: server
INFO: 8546 source files to be analyzed
INFO: 757/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/unittest/AL1203V-D-1
INFO: 1613/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/unittest/AP622V-O-1
INFO: 2274/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/conv/CCNVOUIHIEF
INFO: 3234/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/unittest/PC745V-ADD1
INFO: 4090/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/AP1431V
INFO: 4947/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/LEIDENBG
INFO: 5782/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/PP0513V
INFO: 6259/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/AP8720
INFO: 6919/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/conv/CCNVLSPMEVWY
INFO: 7479/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/GUIFILENAME1
WARN: Trying to redefine the paragraph "ENDS" in file:/build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/GUIFILENAME1 at line 3277, first definition was in file:/build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/C/PROG/FILESPATIENT at line 31
INFO: 8022/8546 files analyzed, current file: /build/builds/JfS_x95k8/0/cobol/sonar-cobol/cobol-src/source/main/PC272RKI
INFO: 8546/8546 source files have been analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 6:14.770s
INFO: Final Memory: 22M/87M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: Line 31 is out of range for file C/IO/MEOPRHDR. File has 30 lines.
	at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43)
	at org.sonar.scanner.DefaultFileLinesContext.checkLineRange(DefaultFileLinesContext.java:63)
	at org.sonar.scanner.DefaultFileLinesContext.setIntValue(DefaultFileLinesContext.java:56)
	at com.sonarsource.cobol.plugin.squid.G.B(Unknown Source)
	at java.base/java.util.BitSet$1BitSetSpliterator.forEachRemaining(BitSet.java:1308)
	at java.base/java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:617)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at java.base/java.util.HashMap$Values.forEach(HashMap.java:1065)
	at com.sonarsource.cobol.plugin.squid.G.A(Unknown Source)
	at com.sonarsource.cobol.plugin.squid.G.execute(Unknown Source)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
section_end:1699876621:step_script
e[0Ksection_start:1699876621:after_script
e[0Ke[0Ke[36;1mRunning after_scripte[0;me[0;m
e[32;1mRunning after script...e[0;m
e[32;1m$ ls -Rltha $COBOL_SRC_LOC > ./cobol_file_list.txte[0;m
section_end:1699876622:after_script
e[0Ksection_start:1699876622:cleanup_file_variables
e[0Ke[0Ke[36;1mCleaning up project directory and file based variablese[0;me[0;m
section_end:1699876622:cleanup_file_variables
e[0Ke[31;1mERROR: Job failed: exit status 1
e[0;m

If there is any other logfile you want you ill have to explicitly ask which one.

Cheers,
Jos

That looks really bad.

It could be related to the analysis cache.
The cache can be disabled by setting the following analysis property:

sonar.cobol.analysisCache.enabled=false

Can you please try that and then tell us if it fixes the error?
Thanks a lot.

Hi Pierre-Yves,

Thanks for your response and for your suggestion.
It happens that in the meantime our SonarQube server has been moved to a new server.
This has caused the problem to disappear for now.
But I am afraid it will come back sooner or later.

My suggestion is to do nothing now, and if the problem returns we turn off the cache.
Then we will be able to determine if switching off the cache actually influences the problem.
Of course we will give you feedback about this when the time comes.

image001.gif

image002.gif

Hi Pierre-Yves,

Last November we reported a problem with an IllegalArgumentException during the scanning of Cobol sources.
This Exception sometimes occurs when a source becomes smaller.
You then suggested we try to disable the cache, to see if that helps.

It took a while for the IllegalArgumentException to reappear.
But this week it did, and I disabled the cache like you suggested.
This ‘fixed’ the error.

To double-check I the re-enabled the cache.
This caused the error to pop up again.

So now for the time being we will work with a disabled cache to prevent this problem from biting us again.

Hopefully you will be able to create a real fix for this problem though:
The time for an analysis is now going up from approx. 7 minutes to approx. 41 minutes.

Met vriendelijke groet / with kind regards,

image001.gif

image002.gif

Hi Jos,

Thanks a lot for reporting this problem.
Turning off the cache is only a workaround.
We definitely need to investigate the problem and provide a fix.
It will be tracked as SONARCOBOL-1693.

Thanks again,
Pierre-Yves