This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/branch-1.7 by this push:
     new 2af801d  ORC-1029: ServiceLoader is not thread-safe, avoid concurrent 
calls (#940)
2af801d is described below

commit 2af801db196ce6dc9ec0a7e913eeb43b6dacca00
Author: Guiyanakaung <[email protected]>
AuthorDate: Thu Oct 21 04:12:50 2021 +0800

    ORC-1029: ServiceLoader is not thread-safe, avoid concurrent calls (#940)
    
    ### What changes were proposed in this pull request?
    
    The previous code reuses LOADER to build DataMask, but the ServiceLoader 
class is not thread-safe and will cause an exception if called concurrently.
    Checking the source code, I found that ServiceLoader.load is a lazy method, 
which is relatively lightweight and only records the relevant information until 
the iterator starts reading before loading the class, so I think it is 
acceptable not to reuse it.
    
    ### Why are the changes needed?
    
    Avoid concurrent calls leading to exceptions.
    
    ### How was this patch tested?
    
    N/A
    
    (cherry picked from commit 19f184acbd02e2ec06f137d24ebefdead709da0c)
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 java/core/src/java/org/apache/orc/DataMask.java | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/java/core/src/java/org/apache/orc/DataMask.java 
b/java/core/src/java/org/apache/orc/DataMask.java
index c92a0fa..021d4f1 100644
--- a/java/core/src/java/org/apache/orc/DataMask.java
+++ b/java/core/src/java/org/apache/orc/DataMask.java
@@ -114,8 +114,6 @@ public interface DataMask {
    * that are accessed through Java's ServiceLoader API.
    */
   class Factory {
-    private static final ServiceLoader<Provider> LOADER =
-        ServiceLoader.load(Provider.class);
 
     /**
      * Build a new DataMask instance.
@@ -130,7 +128,7 @@ public interface DataMask {
     public static DataMask build(DataMaskDescription mask,
                                  TypeDescription schema,
                                  MaskOverrides overrides) {
-      for(Provider provider: LOADER) {
+      for(Provider provider: ServiceLoader.load(Provider.class)) {
         DataMask result = provider.build(mask, schema, overrides);
         if (result != null) {
           return result;

Reply via email to