Bug: stages/stage UI page fails to load when spark reverse proxy is enabled
Status: In Progress | Priority: Major | Resolution: 
Created: 20/Oct/20 15:28
Affects Version/s: 3.0.1

I think we have the same issue reported in SPARK-32467, reproduced with reverse proxy redirects, I'm getting the exact same error in spark UI.

Url page:
{code:java}
http://<master-url>:8080/proxy/app-20201020143315-0005/stages/stage/?id=7&attempt=0{code}
The url above fails to load, looking at the network tab - this request fails:
{code:java}
http://<master-url>:8080/proxy/app-20201020143315-0005/api/v1/applications/app-20201020143315-0005/stages/7/0/taskTable?draw=1&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=20&search%5Bvalue%5D=&search%5Bregex%5D=false&numTasks=1&columnIndexToSort=0&columnNameToSort=Index&_=1603206039549
{code}
Server error stack trace:
{code:java}
/api/v1/applications/app-20201020113310-0004/stages/7/0/taskTable/api/v1/applications/app-20201020113310-0004/stages/7/0/taskTablejavax.servlet.ServletException: java.lang.NullPointerException at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:410) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205) at org.sparkproject.jetty.servlet.ServletHolder.handle(ServletHolder.java:873) at org.sparkproject.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623) at org.apache.spark.ui.HttpSecurityFilter.doFilter(HttpSecurityFilter.scala:95) at org.sparkproject.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610) at org.sparkproject.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540) at org.sparkproject.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) at org.sparkproject.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345) at org.sparkproject.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) at org.sparkproject.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480) at org.sparkproject.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) at org.sparkproject.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247) at org.sparkproject.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) at org.sparkproject.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:753) at org.sparkproject.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220) at org.sparkproject.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.sparkproject.jetty.server.Server.handle(Server.java:505) at org.sparkproject.jetty.server.HttpChannel.handle(HttpChannel.java:370) at org.sparkproject.jetty.server.HttpConnection.onFillable(HttpConnection.java:267) at org.sparkproject.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) at org.sparkproject.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.sparkproject.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) at org.sparkproject.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) at org.sparkproject.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) at org.sparkproject.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) at org.sparkproject.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126) at org.sparkproject.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366) at org.sparkproject.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698) at org.sparkproject.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804) at java.lang.Thread.run(Thread.java:748)Caused by: java.lang.NullPointerException at org.apache.spark.status.api.v1.StagesResource.$anonfun$doPagination$1(StagesResource.scala:175) at org.apache.spark.status.api.v1.BaseAppResource.$anonfun$withUI$1(ApiRootResource.scala:140) at org.apache.spark.ui.SparkUI.withSparkUI(SparkUI.scala:107) at org.apache.spark.status.api.v1.BaseAppResource.withUI(ApiRootResource.scala:135) at org.apache.spark.status.api.v1.BaseAppResource.withUI$(ApiRootResource.scala:133) at org.apache.spark.status.api.v1.StagesResource.withUI(StagesResource.scala:28) at org.apache.spark.status.api.v1.StagesResource.doPagination(StagesResource.scala:174) at org.apache.spark.status.api.v1.StagesResource.$anonfun$taskTable$1(StagesResource.scala:129) at org.apache.spark.status.api.v1.BaseAppResource.$anonfun$withUI$1(ApiRootResource.scala:140) at org.apache.spark.ui.SparkUI.withSparkUI(SparkUI.scala:107) at org.apache.spark.status.api.v1.BaseAppResource.withUI(ApiRootResource.scala:135) at org.apache.spark.status.api.v1.BaseAppResource.withUI$(ApiRootResource.scala:133) at org.apache.spark.status.api.v1.StagesResource.withUI(StagesResource.scala:28) at org.apache.spark.status.api.v1.StagesResource.taskTable(StagesResource.scala:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244) at org.glassfish.jersey.internal.Errors.process(Errors.java:292) at org.glassfish.jersey.internal.Errors.process(Errors.java:274) at org.glassfish.jersey.internal.Errors.process(Errors.java:244) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680) at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394) ... 33 more
{code}
I was able to workaround the issue by either removing the reverse proxy, or use the reverse proxy and manually decode the `order%5B0%5D%5Bdir%5D` to `order[0][dir]`.

Is it possible that this params gets encoded twice when enabling `spark.ui.reverseProxy`? just like the https proxy redirects that was fixed [here|https://github.com/apache/spark/pull/29271]