YangSiJun528 opened a new issue, #729:
URL: https://github.com/apache/fesod/issues/729

   ### Search before asking
   
   - [x] I searched in the [issues](https://github.com/apache/fesod/issues) and 
found nothing similar.
   
   
   ### Fesod version
   
   1.3.0
   
   ### JDK version
   
   17
   
   ### Operating system
   
   macOS 14.6
   
   ### Steps To Reproduce
   
   ```java
   ExcelWriter writerA = FesodSheet
           .write(new File(TestFileUtil.getPath() + "first.xlsx"), 
TestData.class)
           .registerConverter(new ConverterA())
           .build()
           .finish();
   
   ExcelWriter writerB = FesodSheet
           .write(new File(TestFileUtil.getPath() + "second.xlsx"), 
TestData.class)
           .build();
   
   boolean hasCustomConverter = writerB.writeContext()
           .currentWriteHolder()
           .converterMap()
           .values()
           .stream()
           .anyMatch(c -> c instanceof ConverterA);
   
   writerB.finish();
   
   assertFalse(hasCustomConverter, "Unregistered writer inherited converter 
from previous writer");
   ```
   
   ### Current Behavior
   
   Converters registered in one `ExcelWriter` leak to other `ExcelWriter` 
instances, even when the second writer doesn't register any custom converters.
   
   ### Expected Behavior
   
   Each `ExcelWriter` instance should have isolated converters. The second 
writer should only have default converters, not custom converters from the 
first writer.
   
   ### Anything else?
   
   ### Root cause
   
   `DefaultConverterLoader` returns a direct reference to a static mutable map.
   
   This shared reference gets mutated by `AbstractWriteHolder` when custom 
converters are registered, affecting all `ExcelWriter` instances.
   
   ### Proposed fix
   
   Fixing `AbstractWriteHolder` would address the symptom, but 
`DefaultConverterLoader` should return safe copies to prevent this class of 
bugs wherever the API is called.
   
   1. Make static maps immutable
   ```java
   private static final Map<ConverterKey, Converter<?>> defaultWriteConverter;
   
   static {
       Map<ConverterKey, Converter<?>> map = new HashMap<>();
       // ... 
       defaultWriteConverter = Collections.unmodifiableMap(map);
   }
   ```
   
   2. Return defensive copies:
   ```java
   public static Map<ConverterKey, Converter<?>> loadDefaultWriteConverter() {
       return new HashMap<>(defaultWriteConverter);
   }
   ```
   
   Same issue exists in `AbstractReadHolder`.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to