apache / apache/grails-core

error creating GroovyPagesException if nested exception has no stack trace

Open
#14,261 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-gsp
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

GroovyPageView#createGroovyPageException(..) expects the exception that it is building around to have a stack trace. [It is possible for an exception not to have a stack trace](https://plumbr.io/blog/java/on-a-quest-for-missing-stacktraces). This causes a problem in the following code:
```
StackTraceElement[] stackTrace = exception.getStackTrace();
String className = stackTrace[0].getClassName();
```

Stack trace:
```
java.lang.ArrayIndexOutOfBoundsException: 0
at org.grails.web.servlet.view.GroovyPageView.createGroovyPageException(GroovyPageView.java:118)
at org.grails.web.servlet.view.GroovyPageView.handleException(GroovyPageView.java:112)
at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:80)
at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:71)
at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:55)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.grails.web.sitemesh.GrailsLayoutView.renderInnerView(GrailsLayoutView.java:150)
at org.grails.web.sitemesh.GrailsLayoutView.obtainContent(GrailsLayoutView.java:128)
at org.grails.web.sitemesh.GrailsLayoutView.renderTemplate(GrailsLayoutView.java:63)
at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:71)
at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:55)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
...

```
### Steps to Reproduce

This is not an easily reproducible bug.

### Expected Behaviour

I expect to see the original error in my log files or on an error page.

### Actual Behaviour

The log files contain a stack trace from the process of creating a nesting exception, losing the context of the underlying problem.

### Environment Information

- **Operating System**: Centos 6.9
- **Grails Version:** 3.2.1
- **JDK Version:** Oracle 1.8.0_171
- **Container Version (If Applicable):** n/a

Contributor guide

Open the contributing guide

Research direction

Start in GroovyPageView.java at createGroovyPageException, especially the stackTrace lookup at line 118. Inspect how an exception with no stack trace is handled and verify that the original error context is preserved instead of producing the reported ArrayIndexOutOfBoundsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.