yew1eb commented on issue #1602:
URL: https://github.com/apache/auron/issues/1602#issuecomment-3510960356

   I reproduced the failure by loading the class in a test and catch the 
exception stack:
   ```
   try {
       Class.forName("org.apache.spark.sql.auron.NativeConverters$");
   } catch (Throwable t) {
       t.printStackTrace();
   }
   ```
   Result:    
   ```
   java.lang.ExceptionInInitializerError
   Caused by: java.lang.NullPointerException
       at 
org.apache.spark.sql.auron.NativeConverters$.<init>(NativeConverters.scala:91)
       at 
org.apache.spark.sql.auron.NativeConverters$.<clinit>(NativeConverters.scala)
   ```  
   Line 91 in `NativeConverters.scala`:  
   ```
   AuronAdaptor.getInstance.getAuronConfiguration
   ```
   
   **Root cause:**
   The `NoClassDefFoundError` is just a symptom -- the real issue is an NPE 
because `AuronAdaptor.INSTANCE` is `null` on `Executor`. Initialization of 
`INSTANCE` depends on `Shims.get` (a lazy val). If `Shims.get` is not invoked 
early in the `Executor`, `AuronAdaptor.getInstance()` returns `null`, 
triggering the `NPE` during static initialization of `NativeConverters$`.  
   
   
   **Proposed fix:**   
   Make `AuronAdaptor.getInstance()` self-initializing with double-checked 
locking and a unified default initializer:  
   ```
   public static AuronAdaptor getInstance() {
       if (INSTANCE == null) {
           synchronized (AuronAdaptor.class) {
               if (INSTANCE == null) {
                   initializeDefault();
               }
           }
       }
       return INSTANCE;
   }
   
   public static synchronized void initializeDefault() {
       if (INSTANCE == null) {
           initInstance(new SparkAuronAdaptor());
       }
   }
   ```  
   
   And update Shims.scala to use the same entry point:  
   ```
   object Shims {
     lazy val get: Shims = {
       AuronAdaptor.initializeDefault()
       ...
   }
   ```   
   
   This ensures consistent, automatic, thread-safe initialization from both 
`Shims.get` and `AuronAdaptor.getInstance()`, eliminating the fragile ordering 
dependency.  
   
   Happy to open a PR if this approach is approved.  
   @Tartarus0zm  @richox  any feedback ? 
   


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

Reply via email to