Skip to content

fix issue with empty annotation in depiction#1214

Merged
johnmay merged 2 commits intocdk:mainfrom
uli-f:depiction-empty-annotation
Aug 20, 2025
Merged

fix issue with empty annotation in depiction#1214
johnmay merged 2 commits intocdk:mainfrom
uli-f:depiction-empty-annotation

Conversation

@uli-f
Copy link
Copy Markdown
Member

@uli-f uli-f commented Aug 20, 2025

Without any code changes in the non-test space of the code DepictionTest::testAtomPropertyEmptyStringAnnotationLabel fails:

java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 2

	at java.desktop/sun.font.StandardGlyphVector.getGlyphsOutline(StandardGlyphVector.java:1173)
	at java.desktop/sun.font.StandardGlyphVector.getGlyphOutline(StandardGlyphVector.java:433)
	at org.openscience.cdk.renderer.generators.standard.TextOutline.getGlyphCenter(TextOutline.java:196)
	at org.openscience.cdk.renderer.generators.standard.TextOutline.getLastGlyphCenter(TextOutline.java:183)
	at org.openscience.cdk.renderer.generators.standard.StandardGenerator.generateAnnotation(StandardGenerator.java:824)
	at org.openscience.cdk.renderer.generators.standard.StandardGenerator.generateAtomSymbols(StandardGenerator.java:684)
	at org.openscience.cdk.renderer.generators.standard.StandardGenerator.generate(StandardGenerator.java:272)
	at org.openscience.cdk.renderer.generators.standard.StandardGenerator.generate(StandardGenerator.java:103)
	at org.openscience.cdk.depict.DepictionGenerator.generate(DepictionGenerator.java:771)
	at org.openscience.cdk.depict.DepictionGenerator.generate(DepictionGenerator.java:787)
	at org.openscience.cdk.depict.DepictionGenerator.depict(DepictionGenerator.java:384)
	at org.openscience.cdk.depict.DepictionGenerator.depict(DepictionGenerator.java:326)
	at org.openscience.cdk.depict.DepictionTest.testAtomPropertyEmptyStringAnnotationLabel(DepictionTest.java:147)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

I looked through the stack trace and put in a simple check that prevents the ArrayIndexOutOfBoundsException. However, I am not sure if this is the proper place to fix this.

One could ask the question if it is a user input mistake to add an empty String as a property to an atom (atom.setProperty(CDKConstants.COMMENT, "")). In this particular case, preventing the exception from bubbling to the surface seems like a good choice to me.

I also implemented a few code cleanups in the 2nd commit (unused imports, API call simplifications, method references).

uli-f added 2 commits August 20, 2025 15:09
…ionTest; update StandardGenerator to skip empty annotation labels
…r in DepictionTest; simplify stream operations in DepictionTest; remove unused imports and redundant whitespace in StandardGenerator; minor code cleanup in StandardGenerator
@uli-f
Copy link
Copy Markdown
Member Author

uli-f commented Aug 20, 2025

afk for a week, so apologies for any delays in responding to questions here.

@johnmay johnmay merged commit 7f95253 into cdk:main Aug 20, 2025
6 of 7 checks passed
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