Repository navigation
Fix SonarCloud blocker and critical findings in biojava-structure - #1176
Merged
josemduarte merged 11 commits intoDec 5, 2026
Merged
Conversation
Five parsers in biojava-structure built a DocumentBuilderFactory with default settings, which resolves external entities: a crafted alignment, SIFTS or assembly XML could read local files or make network requests (Sonar java:S2755, blocker). Add XMLHelper.newSecureDocumentBuilderFactory() in biojava-core, which disables external entities, external DTDs and XInclude while still accepting DOCTYPE declarations, and use it in AFPChainXMLParser, MultipleAlignmentXMLParser, PdbPairXMLConverter, SiftsXMLParser and BiologicalAssemblyTransformation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use try-with-resources where streams were only closed on the success path, or not at all (Sonar java:S2095, blocker): - SiftsChainToUniprotMapping.download() never closed its input or output stream. - AbstractUserArgumentProcessor, MultipleMcOptimizer, SymmOptimizer, AlignmentResult, AllChemCompProvider, SerializableCache, SiftsChainToUniprotMapping.build() and BlastClustReader leaked when an exception was thrown before the explicit close(). - SynchronizedOutFile leaked the file stream if the GZIPOutputStream constructor failed. - Ccp4Header.openPossiblyGzipped() returns its stream to the caller, but leaked it if reading the magic bytes or opening the gzip wrapper failed. CliTools.configureBean() and Ccp4Header.openPossiblyGzipped() hand their streams to the caller by design, so S2095 is suppressed there with the reason given in a comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The consistency check compared the largest map key and value against the subunit list sizes with ">", but they are 0-based indices, so an index equal to the list size slipped through and failed later in getAlignedSubunits1/2. An empty map threw NoSuchElementException from Collections.max before the code below could mark the relation as DIFFERENT. Use ">=", skip the check for an empty map, and use "||" instead of the non-short-circuit "|" (Sonar java:S2178, blocker). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The flagged fallthroughs (Sonar java:S128, blocker) were all intended, but read like missing breaks. Behaviour is unchanged: - CeSymm: SEQUENCE_FUNCTION and ANGLE order detection and SEQUENCE_FUNCTION refinement fell through to GRAPH_COMPONENT for OPEN alignments. Pick the method up front instead. - ScopDescription.getClassificationId: assign the number of parts per category instead of counting through the cases. Add a test. - AsaCalculator: unexpected Q/E carbons fell through to the default radius; move that default after the switch. - LocalPDBDirectory: FETCH_REMEDIATED with no local file fell into FORCE_DOWNLOAD only to set an already-null file to null; break instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OptimalCECPMain declared its own "params" field, shadowing CeMain's (Sonar java:S2387, blocker). setParameters() only updated the subclass field, but CeMain.align(Atom[], Atom[]) passes CeMain's field down, so the CP options came from the user's parameters while the CE options (window size, RMSD thresholds, ...) silently stayed at their defaults. Rename the subclass field to cpParams and have the constructor and setParameters() store the same object in CeMain's field too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The private field "m" (gap-create + gap-extend) differed from the field "M" (length of protein 1) only by case (Sonar java:S1845, blocker). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These tests only checked that nothing threw (Sonar java:S2699, blocker): - TestBond: the structures that used to crash formBonds() now must load with at least one chain. - TestVeryLongFileName: toPDB() must wrap a long unbroken title into records of at most 80 columns. - TestChemCompProvider.testNormalStructure: 4HHM must load with the ZipChemCompProvider and have chains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DSSPParser set the partner of the fourth H-bond column (O-->H-N) on donor2 but its energy on donor1, so every state parsed from a DSSP file had donor1's energy overwritten and no donor2 energy. The existing test did not notice because SecStrucState.equals ignores energies. Found while adding the default case Sonar asked for (java:S131). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A CathDomall line with fewer than three fields failed with a bare ArrayIndexOutOfBoundsException, and a SCOP comments line made only of "!" did the same, while a blank one failed in Integer.parseInt (Sonar javabugs:S6466). Throw an IOException naming the line instead, and skip blank lines in the SCOP comments file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AllChemCompProvider.loadAllChemComps() only touches static state, so make it static. DownloadChemCompProvider lazily created its static fallback provider from an instance method without synchronisation; ReducedChemCompProvider is cheap to create, so create it once when the class is loaded (Sonar java:S2696). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Behaviour-preserving cleanups for the remaining critical findings that point at possible bugs: - Default cases for switches on a random direction (MultipleMcOptimizer, SymmOptimizer) that throw if reached, and default cases that fail in TestSpaceGroup, where an unexpected fold type passed silently (S131). - Braces where indentation suggested a different nesting in the PDP code and HelicalRepeatUnit, and "\t" instead of raw tabs in literals (S3973, S2479). - Double.compare in the FragmentJoiner and RotationGroup comparators, which keeps them consistent for NaN (S9148). - replace() instead of replaceAll() for literal characters (S5361). - ThreadLocalRandom instead of a new Random per default seed (S2119). - Site.toPDB(): one loop counter in the for clause, and drop a replaceFirst() whose result was discarded (S1994). - Astral: try-with-resources (S2093). - StructureName: check for a missing PDB ID instead of relying on the PdbId constructor throwing for null (S6416). 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-structure, and the critical findings that point at possible bugs. Findings in code that #1168 removes (Jama, MMTF,GuiWrapper,AlignmentProgressListener) are skipped.Bugs fixed (each with a test that failed first)
AFPChainXMLParser,MultipleAlignmentXMLParser,PdbPairXMLConverter,SiftsXMLParser,BiologicalAssemblyTransformation) resolved external entities, so a crafted file could read local files or make network requests. AddsXMLHelper.newSecureDocumentBuilderFactory()inbiojava-core.DSSPParser: the fourth H-bond column's energy went toDonor1instead ofDonor2, so every parsed state had a wrongDonor1energy and noDonor2energy. The existing test missed it becauseSecStrucState.equalsignores energies.OptimalCECPMain: aftersetParameters(p),align(ca1, ca2)used default CE settings (window size, RMSD thresholds), because a shadowingparamsfield was never passed down.QsAlignResult.setSubunitMap: off-by-one bounds check, and an empty map crashed withNoSuchElementException.Other fixes
SiftsChainToUniprotMapping.download()never closed its streams.CliTools.configureBeanandCcp4Header.openPossiblyGzippedhand their streams to the caller by design, so the warning is suppressed there with the reason in a comment.IOExceptionnaming the line instead ofArrayIndexOutOfBoundsException.switchfallthroughs inCeSymm,ScopDescription,AsaCalculatorandLocalPDBDirectoryare made explicit. No behaviour change.TestSpaceGroupnow fails on an unexpected fold type instead of passing silently.Double.comparein comparators,replacefor single characters,ThreadLocalRandom, a discardedreplaceFirstinSite.toPDB().Not addressed
clone()findings (S2975): replacing them with copy constructors is an API change, now item 10 in BioJava 8.0 plan: Java 21, a leaner, library-only BioJava #1168.BridgeType.name/SecStrucType.name(S1845): public fields, so renaming them breaks the API for a naming-only issue.EcodInstallation.parseManualRepreturnsnullon purpose, andAstral:222andClusterDomains:234are safe as written.Testing
CeSymmfallback for open alignments, which would need a structure with translational symmetry. The rewrite was checked by reading the old and new code side by side.🤖 Generated with Claude Code