[ 
https://issues.apache.org/jira/browse/CSV-302?focusedWorklogId=818607&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-818607
 ]

ASF GitHub Bot logged work on CSV-302:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Oct/22 21:24
            Start Date: 19/Oct/22 21:24
    Worklog Time Spent: 10m 
      Work Description: sman-81 commented on code in PR #276:
URL: https://github.com/apache/commons-csv/pull/276#discussion_r999946899


##########
src/main/java/org/apache/commons/csv/CSVFormat.java:
##########
@@ -2280,6 +2279,27 @@ private void validate() throws IllegalArgumentException {
         }
     }
 
+    private Object readResolve() throws ObjectStreamException {
+        // check whether field duplicateHeaderMode (as of 1.10.0) was found in 
serialized form
+        // if not, set from boolean allowDuplicateHeaderNames
+        if (duplicateHeaderMode == null) {
+            setFieldValue("duplicateHeaderMode",
+                    allowDuplicateHeaderNames ? DuplicateHeaderMode.ALLOW_ALL 
: DuplicateHeaderMode.DISALLOW);
+        }
+        return this;
+    }
+
+    private void setFieldValue(final String fieldName, final Object value) {
+        try {
+            Field fld = getClass().getDeclaredField(fieldName);
+            fld.setAccessible(true); // make field non-final
+            fld.set(this, value);
+            fld.setAccessible(false);
+        } catch (Exception ex) {

Review Comment:
   The code in `try` might throw any of `NoSuchFieldException, 
SecurityException, IllegalArgumentException, IllegalAccessException`
   `ObjectStreamException` is abstract, but a subclass can be used. 
`InvalidClassException` seems like the good choice.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 818607)
    Time Spent: 1h 20m  (was: 1h 10m)

> CSVFormat.duplicateHeaderMode requires default for backward compatibility
> -------------------------------------------------------------------------
>
>                 Key: CSV-302
>                 URL: https://issues.apache.org/jira/browse/CSV-302
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.10.0
>            Reporter: Markus Spann
>            Priority: Minor
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> The member in class {{CSVFormat}}
> {code:java}
> boolean allowDuplicateHeaderNames{code}
>  was recently replaced by 
> {code:java}
> DuplicateHeaderMode duplicateHeaderMode{code}
> The boolean defaults to {{{}false{}}}, while the member of type 
> {{DuplicateHeaderMode}} defaults to {{{}null{}}}.
> {{duplicateHeaderMode}} must be initialized with {{DISALLOW}} for backward 
> compatibility.
> The change is also problematic with regards to serialization. The class is 
> serializable and {{serialVersionUID}} is unchanged between versions. The 
> boolean setting {{allowDuplicateHeaderNames}} in an object serialized in 
> version 1.9.0 or earlier would always be de-serialized to 
> {{duplicateHeaderMode = null}} in the current head.
> To handle the code changes correctly, customized de-serialization would need 
> to be implemented.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to