Repository navigation
Fix SonarCloud blocker and critical findings in biojava-core - #1177
Merged
Merged
Conversation
XMLHelper.inputStreamToDocument(), used by loadXML() and so by the BLAST XML parser, enabled FEATURE_SECURE_PROCESSING only after creating its DocumentBuilder, which has no effect, and that feature does not block external entities anyway: a crafted file could read local files (Sonar java:S2755, blocker). Use newSecureDocumentBuilderFactory() instead. Also stop the Transformer in outputToStream() from fetching external DTDs or stylesheets, and use the secure factory in StringManipulationHelper.equalsToXml(). That method is documented as not implemented and always throws, so mark it @deprecated for removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- InputStreamProvider: for .zip and .jar files the stream to the first entry was returned without any way to close the ZipFile/JarFile behind it, so each open leaked a file descriptor until garbage collection, and an archive with no entries leaked before throwing (Sonar java:S2095, blocker). Return a stream that also closes the archive. When a GZIP or .Z wrapper fails to open, close the underlying stream. New tests, including one that checks the open file descriptor count. - ClasspathResource: try-with-resources for the pre-cache copy, and close the stream if it turns out not to be GZIP (S2093). - IOUtils.print: try-with-resources, and write through a plain Writer so write errors are reported as the javadoc says, rather than swallowed by PrintWriter (S2093). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The program name from a "# TBLASTN 2.2.29+" header kept its "# " prefix because String.replace() takes a literal, not the regex "#\s" it was given. Use replaceFirst. - A row with fewer than the 12 standard columns threw ArrayIndexOutOfBoundsException (Sonar javabugs:S6466); throw the ParseException that createObjects() already declares. - createObjects() never closed its Scanner; use try-with-resources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ABITrace documents an IllegalArgumentException for data that is not a valid ABI file, but isABI() read bytes 0-2 and 128-130 without checking the length, so short data threw ArrayIndexOutOfBoundsException (Sonar javabugs:S6466). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
initMatrix() read fields 3 and 6 of the "M rows = ..., cols = ..." line without checking they exist, so a malformed header threw ArrayIndexOutOfBoundsException out of parse() (Sonar javabugs:S6466). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SearchIO cached one ResultFactory instance per file extension in a static map and handed that same instance to every SearchIO. Parsers keep per-file state, so reading a headerless BLAST tabular file after one with a header reported the first file's program name. The cache was also published before it was filled, so another thread could see it half empty (Sonar java:S2696). Cache the factory class per extension instead, loaded once through a holder class, and create a new factory for each SearchIO. Also stop the "# BLAST processed N queries" trailer from overwriting the program name: only accept a header line with a version after the name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Behaviour-preserving cleanups: - AbstractFeature comparators: compare the integer positions with Integer.compare instead of widening them to double (S9148, S3973). - SimpleProfile and MultipleSequenceAlignment.toString(StringFormat): move the CLUSTAL/default group to the end of the switch (S4524). - replace() instead of replaceAll() where the pattern is a literal, in MultipleSequenceAlignment, GenbankSequenceParser, GenericInsdcHeaderFormat and FileDownloadUtils (S5361). - FastaReaderTest: explicit default cases in switches that only check selected sequences (S131). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For a negative-strand gene, getSequenceAsString(begin, end, NEGATIVE) already returns the reverse complement, and the method then complemented it again, returning the forward sequence reversed. This is the bug fixed in CDSSequence.getCodingSequence by biojava#1016, still present in GeneSequence. FastaGeneWriter, its only caller, wrote such genes reversed but not complemented. Found by replacing an assertion-less test (Sonar java:S2699) with a real check. FastaGeneWriterTest expected the old output; its expectation is corrected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These tests only checked that nothing threw (Sonar java:S2699, blocker): - BlastXMLParserTest: parsing without a file throws IllegalStateException; storeObjects() throws the documented UnsupportedOperationException. - BlastTabularParserTest.testSetFile only called a setter with null and had nothing to check; setFile is covered by testCreateObjects. Removed. - ChromosomeSequenceTest: removing a missing gene leaves no genes; two empty placeholder tests removed (addGene/getGene are covered above). - TranslationTest: table 1 and "UNIVERSAL" are the same table. - GenbankCookbookTest: the local GenBank files give non-empty, identical results through GenbankReaderHelper and GenbankReader; the NCBI part checks that an accession was parsed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
josemduarte
added a commit
that referenced
this pull request
Dec 5, 2026
It was disabled with "seems to complement twice???", had no assertion and only printed the result. That double complement was fixed in #1177, and negativeStrandSequence5PrimeTo3PrimeIsReverseComplement covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Works through the SonarCloud blocker findings in
biojava-core, and the critical findings that point at possible bugs.Bugs fixed (each with a test that failed first)
GeneSequence.getSequence5PrimeTo3Prime(), negative strand: returned the sequence reversed but not complemented.getSequenceAsString(begin, end, NEGATIVE)already gives the reverse complement, and the method complemented it again. This is the bug o.b.n.core.sequence.CDSSequence doesn't reverse-complement correctly #1016 fixed inCDSSequence;GeneSequencewas missed.FastaGeneWriter(its only caller) wrote such genes that way, andFastaGeneWriterTestexpected that output; the expectation is corrected.SearchIOshared one parser across readers: it cached oneResultFactoryinstance per extension and gave it to everySearchIO. Parsers keep per-file state, so a headerless BLAST tabular file read after one with a header reported the first file's program name. The cache was also published before it was filled. It now caches classes and creates a parser perSearchIO.#prefix (replacewas given a regex), and the# BLAST processed N queriestrailer overwrote it.XMLHelper.inputStreamToDocument()(and soloadXML()and the BLAST XML parser) enabled its secure-processing feature after building the parser, which has no effect and doesn't block external entities anyway. It now uses the hardened factory, and theTransformerno longer fetches external DTDs or stylesheets.InputStreamProvider: for.zip/.jar, closing the returned stream didn't close the archive, which leaked one file descriptor per read. A new test checks the open file descriptor count. Failed GZIP/.Zwrapping now closes the underlying stream.Other fixes
ArrayIndexOutOfBoundsException: short BLAST tabular rows throwParseException, short ABI data throws the documentedIllegalArgumentException, and a malformed AAindex matrix header throwsIOException.ClasspathResourceandIOUtils.print, which now also reports write errors as its javadoc says. The BLAST tabular parser now closes itsScanner.StringManipulationHelper.equalsToXml: marked@Deprecated. It is documented as unimplemented and always throws.nullare removed.Integer.comparein theAbstractFeaturecomparators,defaultlast in two switches,replacefor literal patterns, and explicitdefaults inFastaReaderTest.Not addressed
AbstractFeature.TYPE(S1845): a public constant, so renaming it breaks the API.FileDownloadUtilstemp file (S5443): a false positive.Files.createTempFilecreates an owner-only file with a random name.equalsToXml(S3516): stays flagged until 8.0 removes it with the other deprecated APIs (BioJava 8.0 plan: Java 21, a leaner, library-only BioJava #1168 item 7).Testing
mvn teston every module exceptbiojava-integrationtestpasses locally (about 1,450 tests, 0 failures).🤖 Generated with Claude Code