You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2026/10/07 20:32:20 UTC
svn commit: r1938883 - in pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/annotation test/java/org/apache/pdfbox/pdmodel/interactive/annotation
Author: tilman
Date: Wed Oct 7 20:32:20 2026
New Revision: 1938883
Log:
PDFBOX-6270: don't let the annotation get dirty, as suggested by Jakob Heher and ChatGPT
Added:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidgetTest.java (contents, props changed)
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidget.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidget.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidget.java Wed Oct 7 20:32:16 2026 (r1938882)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidget.java Wed Oct 7 20:32:20 2026 (r1938883)
@@ -53,7 +53,10 @@ public class PDAnnotationWidget extends
public PDAnnotationWidget(COSDictionary field)
{
super(field);
- getCOSObject().setName(COSName.SUBTYPE, SUB_TYPE);
+ if (!SUB_TYPE.equals(getSubtype()))
+ {
+ getCOSObject().setName(COSName.SUBTYPE, SUB_TYPE);
+ }
}
/**
Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidgetTest.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationWidgetTest.java Wed Oct 7 20:32:20 2026 (r1938883)
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.interactive.annotation;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocumentState;
+import org.apache.pdfbox.cos.COSName;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import org.junit.jupiter.api.Test;
+
+class PDAnnotationWidgetTest
+{
+
+ /**
+ * PDFBOX-6270: check that a correct annotation doesn't get dirty.
+ */
+ @Test
+ void testDontDirtyOnConstruction()
+ {
+ // setup - build a cosstream that will accept update flags:
+ COSDictionary dict = new COSDictionary();
+ COSDocumentState state = new COSDocumentState();
+ state.setParsing(false);
+ dict.getUpdateState().setOriginDocumentState(state);
+
+ // set subtype correctly:
+ // (this stands in for an annotation widget that was parsed from an existing document)
+ dict.setItem(COSName.TYPE, COSName.ANNOT);
+ dict.setName(COSName.SUBTYPE, PDAnnotationWidget.SUB_TYPE);
+ dict.setNeedToBeUpdated(false);
+ assertFalse(dict.isNeedToBeUpdated());
+
+ // construct a PDAnnotationWidget wrapper around it:
+ new PDAnnotationWidget(dict);
+
+ assertFalse(dict.isNeedToBeUpdated());
+ }
+}