Bug 61604 - IllegalStateException in SmapStratum on empty JSP
Summary: IllegalStateException in SmapStratum on empty JSP
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 9.0.1
Hardware: PC All
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2017-10-10 14:34 UTC by stef.an
Modified: 2017-10-10 19:26 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description stef.an 2017-10-10 14:34:37 UTC
We use a JSP that is included at several points to inject data into pages. At the moment the whole content is commented out.

Tomcat 8.5 (production environment) ignores that page, respectively generates no output as expected. Tomcat 9.0.1 (development environment) throws an IllegalstateException. This is caused by a change in SmapStratum, which previously returned null on getString() if lineData was null, now it throws an unhandled exception.


Create an "empty" JSP or one containing only JSP comments and using trimDirectiveWhitespaces="true":

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=utf-8" language="java" import="java.util.Vector" errorPage="" trimDirectiveWhitespaces="true" %>
<%-- This is a comment --%>


        at org.apache.jasper.compiler.SmapStratum.getSmapStringInternal(SmapStratum.java:318)
        at org.apache.jasper.compiler.SmapStratum.getSmapString(SmapStratum.java:304)
        at org.apache.jasper.compiler.SmapUtil.installSmap(SmapUtil.java:145)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:473)

Expected result:

an empty page
Comment 1 stef.an 2017-10-10 14:57:06 UTC
Sorry, of course lineData is not null at that point, it is the empty array causing the exception being thrown.

// print our StratumSection, FileSection, and LineSections
if (fileNameList.size() == 0 || lineData.size() == 0) {
  throw new IllegalStateException();
Comment 2 Remy Maucherat 2017-10-10 15:25:44 UTC
So this was done during the (major) 49176 enhancement in r1800201.
Switching back to returning null will likely cause some NPEs in some cases, but this used to be the case before from what I can see.
Comment 3 Mark Thomas 2017-10-10 19:01:01 UTC
Going back to the SMAP spec, it is legal for there to be zero LineInfo lines so the lineData.size() == 0 test can be removed.

I'll double-check the rest of the spec while I am at it.
Comment 4 Mark Thomas 2017-10-10 19:26:59 UTC
Thanks for the report. This has been fixed for 9.0.2 onwards.