[ 
https://issues.apache.org/jira/browse/HADOOP-18814?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17765295#comment-17765295
 ] 

ASF GitHub Bot commented on HADOOP-18814:
-----------------------------------------

teamconfx opened a new pull request, #6076:
URL: https://github.com/apache/hadoop/pull/6076

   ### Description of PR
   https://issues.apache.org/jira/browse/HADOOP-18814
   This PR adds a check before casting to RemoteException to avoid hiding the 
actual exception.
   
   ### How was this patch tested?
   (1) Set hadoop.security.authentication to kerberos
   (2) Run test TestRPC#testReaderExceptions
   The test throws the actual exception stating that "Client cannot 
authenticate via:[KERBEROS]".
   
   ### For code changes:
   
   - [x] Does the title or this PR starts with the corresponding JIRA issue id 
(e.g. 'HADOOP-17799. Your PR title ...')?
   - [ ] Object storage: have the integration tests been executed and the 
endpoint declared according to the connector-specific documentation?
   - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`, 
`NOTICE-binary` files?
   
   




> Direct class cast causes ClassCastException in TestRPC#testReaderExceptions
> ---------------------------------------------------------------------------
>
>                 Key: HADOOP-18814
>                 URL: https://issues.apache.org/jira/browse/HADOOP-18814
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: conf, ipc
>            Reporter: ConfX
>            Priority: Critical
>         Attachments: reproduce.sh
>
>
> h2. What happened:
> Test {{TestRPC#testReaderExceptions}} assumes there is a RemoteException has 
> been thrown and directly cast the root cause of {{ServiceException}} to 
> {{{}RemoteException{}}}. But this cast may lead to ClassCastException when 
> the root cause exception is not {{{}RemoteException{}}}.
> h2. Buggy code:
> {code:java}
> @Test (timeout=30000)
> public void testReaderExceptions() throws Exception {
>       ...
>       try {
>         FakeRequestClass.exception = doDisconnect ? rseFatal : rseError;
>         proxy.ping(null, newEmptyRequest());
>         fail(reqName + " didn't fail");
>       } catch (ServiceException e) {
>         RemoteException re = (RemoteException)e.getCause();       // <--- 
> Here the test assumes the root cause is RemoteException
>         assertEquals(reqName, expectedIOE, re.unwrapRemoteException());
>       } {code}
> h2. How to reproduce:
> (1) Set {{hadoop.security.authentication}} to {{kerberos}}
> (2) Run test {{TestRPC#testReaderExceptions}}
> h2. Stack trace:
> {code:java}
> java.lang.ClassCastException: class java.io.IOException cannot be cast to 
> class org.apache.hadoop.ipc.RemoteException (java.io.IOException is in module 
> java.base of loader 'bootstrap'; org.apache.had
> oop.ipc.RemoteException is in unnamed module of loader 'app')                 
>  
>         at 
> org.apache.hadoop.ipc.TestRPC.testReaderExceptions(TestRPC.java:1742)         
>                                                                               
>                                 
>         at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:566)         
>                      
>         at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
>         at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>      
>         at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
>         at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at 
> org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
>         at 
> org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
>                                                                               
>             
>         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 
>                      
>         at java.base/java.lang.Thread.run(Thread.java:829)   {code}
> h2. Fix:
> A better way to do is to firstly check whether the root cause is 
> RemoteException, if not, fail the test rather than causing the 
> CastClassException:
> {code:java}
>   try {
>     FakeRequestClass.exception = doDisconnect ? rseFatal : rseError;
>     proxy.ping(null, newEmptyRequest());
>     fail(reqName + " didn't fail");
>   } catch (ServiceException e) {
>     if (e.getCause() instanceof RemoteException) {
>       RemoteException re = (RemoteException)e.getCause();
>       assertEquals(reqName, expectedIOE, re.unwrapRemoteException());
>     } else {
>       fail(reqName + " didn't fail with RemoteException");
>     }
>   } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to