elharo commented on PR #116:
URL: https://github.com/apache/xerces-j/pull/116#issuecomment-5004756319

   An alternative approach that avoids the separate forked JVM: instead of 
reading the system property once in a `static final` field, change 
`TypeValidator.getDataLength()` to call `Boolean.getBoolean(...)` directly. The 
system property is the public API — no new setter needed. The performance 
impact of reading a system property on each string-length check is negligible 
for a rarely-used debug flag.
   
   ```java
   // TypeValidator.java
   public int getDataLength(Object value) {
       if (value instanceof String) {
           final String str = (String)value;
           if (!isCodePointCountEnabled()) {
               return str.length();
           }
           return getCodePointLength(str);
       }
       return -1;
   }
   
   private static boolean isCodePointCountEnabled() {
       return AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
           
Boolean.getBoolean("org.apache.xerces.impl.dv.xs.useCodePointCountForStringLength")
       );
   }
   ```
   
   Then `SurrogatePairLengthTest` would work in the shared JVM — just set the 
property via `System.setProperty()` and let it be read lazily.
   


-- 
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