You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by "skytin1004 (via GitHub)" <gi...@apache.org> on 2026/05/07 14:30:48 UTC

[PR] fix: avoid recursive hashCode in write holder contexts [fesod]

skytin1004 opened a new pull request, #911:
URL: https://github.com/apache/fesod/pull/911

   ## Purpose of the pull request
   
   Part of #889.
   
   This PR focuses only on the recursive holder/context `hashCode()` path.
   
   It intentionally does not change converter lookup behavior. The converter lookup behavior will be handled separately because it can fail independently when a global converter is registered with a non-null `supportExcelTypeKey()`.
   
   ## What's changed?
   
   - Exclude `workbookWriteHandlerContext` from `WriteWorkbookHolder` equality/hashCode generation.
   - Exclude parent/cache holder references from `WriteSheetHolder` and `WriteTableHolder` equality/hashCode generation.
   - Add a focused regression test for the recursive workbook handler context path and the initialized workbook/sheet/table holder graph.
   
   ## Verification
   
   ```bash
   bash mvnw -pl fesod-common,fesod-shaded -am -DskipTests install
   bash mvnw -pl fesod-sheet -Dtest=WriteHolderHashCodeTest,CustomConverterTest -Dmaven.test.skip=false test
   bash mvnw -pl fesod-sheet -Dmaven.test.skip=false test
   ```
   
   ## Checklist
   
   - [x] I have read the [Contributor Guide](https://fesod.apache.org/community/contribution/).
   - [x] I have written the necessary doc or comment.
   - [x] I have added the necessary unit tests and all cases have passed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: avoid recursive hashCode in write holder contexts [fesod]

Posted by "alaahong (via GitHub)" <gi...@apache.org>.
alaahong commented on code in PR #911:
URL: https://github.com/apache/fesod/pull/911#discussion_r3790849692


##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/write/metadata/holder/WriteHolderHashCodeTest.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.fesod.sheet.write.metadata.holder;
+
+import org.apache.fesod.sheet.write.handler.context.WorkbookWriteHandlerContext;
+import org.apache.fesod.sheet.write.metadata.WriteSheet;
+import org.apache.fesod.sheet.write.metadata.WriteTable;
+import org.apache.fesod.sheet.write.metadata.WriteWorkbook;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class WriteHolderHashCodeTest {
+
+    @Test
+    void workbookHolderHashCodeShouldNotRecurseThroughWorkbookHandlerContext() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        workbookHolder.setWorkbookWriteHandlerContext(new WorkbookWriteHandlerContext(null, workbookHolder));
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+    }
+
+    @Test
+    void writeHolderHashCodeShouldNotRecurseThroughParentAndInitializedHolderReferences() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        WriteSheetHolder sheetHolder = new WriteSheetHolder(writeSheet(), workbookHolder);
+        WriteTableHolder tableHolder = new WriteTableHolder(writeTable(), sheetHolder);
+
+        workbookHolder.getHasBeenInitializedSheetIndexMap().put(sheetHolder.getSheetNo(), sheetHolder);
+        workbookHolder.getHasBeenInitializedSheetNameMap().put(sheetHolder.getSheetName(), sheetHolder);
+        sheetHolder.getHasBeenInitializedTable().put(tableHolder.getTableNo(), tableHolder);
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+        Assertions.assertDoesNotThrow(sheetHolder::hashCode);
+        Assertions.assertDoesNotThrow(tableHolder::hashCode);

Review Comment:
   @skytin1004  please kindly help if would like to update this. it's optional for this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: avoid recursive hashCode in write holder contexts [fesod]

Posted by "skytin1004 (via GitHub)" <gi...@apache.org>.
skytin1004 commented on code in PR #911:
URL: https://github.com/apache/fesod/pull/911#discussion_r3273286948


##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/write/metadata/holder/WriteHolderHashCodeTest.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.fesod.sheet.write.metadata.holder;
+
+import org.apache.fesod.sheet.write.handler.context.WorkbookWriteHandlerContext;
+import org.apache.fesod.sheet.write.metadata.WriteSheet;
+import org.apache.fesod.sheet.write.metadata.WriteTable;
+import org.apache.fesod.sheet.write.metadata.WriteWorkbook;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class WriteHolderHashCodeTest {
+
+    @Test
+    void workbookHolderHashCodeShouldNotRecurseThroughWorkbookHandlerContext() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        workbookHolder.setWorkbookWriteHandlerContext(new WorkbookWriteHandlerContext(null, workbookHolder));
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+    }
+
+    @Test
+    void writeHolderHashCodeShouldNotRecurseThroughParentAndInitializedHolderReferences() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        WriteSheetHolder sheetHolder = new WriteSheetHolder(writeSheet(), workbookHolder);
+        WriteTableHolder tableHolder = new WriteTableHolder(writeTable(), sheetHolder);
+
+        workbookHolder.getHasBeenInitializedSheetIndexMap().put(sheetHolder.getSheetNo(), sheetHolder);
+        workbookHolder.getHasBeenInitializedSheetNameMap().put(sheetHolder.getSheetName(), sheetHolder);
+        sheetHolder.getHasBeenInitializedTable().put(tableHolder.getTableNo(), tableHolder);
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+        Assertions.assertDoesNotThrow(sheetHolder::hashCode);
+        Assertions.assertDoesNotThrow(tableHolder::hashCode);

Review Comment:
   @alaahong Yes, this also changes equals behavior. That was intentional, because Lombok applies the exclude list to both equals() and hashCode().
   
   The excluded fields are only used during the write process and they can form cycles. So if we only think about hashCode(), the same kind of recursion risk can still remain in equals().
   
   If you prefer, I can update the PR description and add an equals regression assertion to make this explicit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: avoid recursive hashCode in write holder contexts [fesod]

Posted by "delei (via GitHub)" <gi...@apache.org>.
delei merged PR #911:
URL: https://github.com/apache/fesod/pull/911


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: avoid recursive hashCode in write holder contexts [fesod]

Posted by "alaahong (via GitHub)" <gi...@apache.org>.
alaahong commented on code in PR #911:
URL: https://github.com/apache/fesod/pull/911#discussion_r3260620188


##########
fesod-sheet/src/test/java/org/apache/fesod/sheet/write/metadata/holder/WriteHolderHashCodeTest.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.fesod.sheet.write.metadata.holder;
+
+import org.apache.fesod.sheet.write.handler.context.WorkbookWriteHandlerContext;
+import org.apache.fesod.sheet.write.metadata.WriteSheet;
+import org.apache.fesod.sheet.write.metadata.WriteTable;
+import org.apache.fesod.sheet.write.metadata.WriteWorkbook;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class WriteHolderHashCodeTest {
+
+    @Test
+    void workbookHolderHashCodeShouldNotRecurseThroughWorkbookHandlerContext() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        workbookHolder.setWorkbookWriteHandlerContext(new WorkbookWriteHandlerContext(null, workbookHolder));
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+    }
+
+    @Test
+    void writeHolderHashCodeShouldNotRecurseThroughParentAndInitializedHolderReferences() {
+        WriteWorkbookHolder workbookHolder = new WriteWorkbookHolder(new WriteWorkbook());
+        WriteSheetHolder sheetHolder = new WriteSheetHolder(writeSheet(), workbookHolder);
+        WriteTableHolder tableHolder = new WriteTableHolder(writeTable(), sheetHolder);
+
+        workbookHolder.getHasBeenInitializedSheetIndexMap().put(sheetHolder.getSheetNo(), sheetHolder);
+        workbookHolder.getHasBeenInitializedSheetNameMap().put(sheetHolder.getSheetName(), sheetHolder);
+        sheetHolder.getHasBeenInitializedTable().put(tableHolder.getTableNo(), tableHolder);
+
+        Assertions.assertDoesNotThrow(workbookHolder::hashCode);
+        Assertions.assertDoesNotThrow(sheetHolder::hashCode);
+        Assertions.assertDoesNotThrow(tableHolder::hashCode);

Review Comment:
   any change on the equals behavior?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org