stoty commented on PR #7892:
URL: https://github.com/apache/hadoop/pull/7892#issuecomment-3249122071

   I spent some time trying to implement that @szetszwo .
   
   At the core, we'd need a wrapper like this:
   
   ` 
     public static class SubjectInheritingWrapper extends Thread {
   
       private Thread wrapped;
       private Subject startSubject;
   
       public SubjectInheritingWrapper(Thread wrapped) {
         this.wrapped = wrapped;
       }
   
       @Override
       public synchronized void start() {
         startSubject = SubjectUtil.current();
         wrapped.start();
       }
   
       @Override
       public final void run() {
         SubjectUtil.doAs(startSubject, new PrivilegedAction<Void>() {
   
           @Override
           public Void run() {
             wrapped.run();
             return null;
           }
   
         });
       }
       
       public void interrupt() {
         wrapped.interrupt();
       }
       
       public boolean isInterrupted() {
         return wrapped.isInterrupted();
       }
       
       // setDaemon is final!!!
       public void setDaemon()...
     }`
     
   run() and start() are wrappable, but Thread is full of **final** methods 
which cannot be overriden, and would not work on the wrapper (which is never 
actually started, only the wrapped thread is).
   
   Say, we want to call setDaemon() on the wrapper. Since we cannot override 
it, it would set the daemon flag on the wrapper, not the wrapped thread, which 
is never even start() ed , and wouldn't work.
   
   So a wrapper like this would invisibly break the Thread contract in many 
ways.
   I don't think it's worth the risk of the hidden bugs that this could cause.
   


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