Skip to content

Move the InChI Readers to cdk-inchi module.#1235

Merged
egonw merged 2 commits intomainfrom
cdk-inchi-cleanup
Oct 4, 2025
Merged

Move the InChI Readers to cdk-inchi module.#1235
egonw merged 2 commits intomainfrom
cdk-inchi-cleanup

Conversation

@johnmay
Copy link
Copy Markdown
Member

@johnmay johnmay commented Oct 2, 2025

No description provided.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Oct 2, 2025

@egonw egonw merged commit 285da9b into main Oct 4, 2025
11 checks passed
logger.debug("Parsing atom data: ", atomsEncoding);

Pattern pattern = Pattern.compile("([A-Z][a-z]?)(\\d+)?(.*)");
Pattern pattern = Pattern.compile("([A-Z][a-z]?)(\\d++)?(.*+)");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never seen this extra + syntax before. Got some info for me? Love to read up on this.

@johnmay
Copy link
Copy Markdown
Member Author

johnmay commented Oct 4, 2025

See "Possessive quantifiers" https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html

A possessive quantifier is just like the greedy quantifier, but it doesn't backtrack. So it starts out with .* matching the entire string, leaving nothing unmatched. Then there is nothing left for it to match with the f in the regex. Since the possessive quantifier doesn't backtrack, the match fails there.

Not always what you want but it is in this case and avoids the SonarCloud warning of denial of service. You need to be careful though as

a+ab matches aaaaaaaaab
but
a++ab doesn't matches aaaaaaaaab

The a's get all consumed and doesn't backtrack.

The other option is using a different regex library (e.g. dk.brics.Automata) which use a state machine to matche in linear time.

@johnmay johnmay deleted the cdk-inchi-cleanup branch March 3, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants