smalinin / json-template

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

Unbalanced section push and pop in the Java implementation #57

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When the data is missing for the template section, the SectionStatement.java 
caused the exception in public Object pushSection(String sectionName) of the 
file ScopedContext.java. It starts happening for the second section of missing 
data.
Please see my fix bellow.

Regards,
Louis
///////////////////////////////////////////////////////////

public void execute(ScopedContext context, ITemplateRenderCallback callback) {
        // push a context first
        Object cursorPosition = context
                .pushSection(this.block.getSectionName());
        if (!context.isEmptyContext(cursorPosition)) {
            TemplateExecutor.execute(this.block.getStatements(), context,
                    callback);
            //context.pop(); // Louis fix, remove this line
        } else {
            TemplateExecutor.execute(this.block.getStatements("or"), context,
                    callback);
        }
        context.pop(); // Louis fix, add this line
    }

////////////////////////////////////////////////////////

Original issue reported on code.google.com by louis...@rogers.com on 23 Jul 2010 at 7:36

GoogleCodeExporter commented 9 years ago
Thanks, Louis, for pointing to issue source. But general problem is that while 
processing 'or' statement stack top contains 'null' value. This value remained 
after unsuccessful lookup for beginning of 'section' statement and must be 
removed before executing 'or' section. So fix should looks like this
///////////////////////////////////////////////////////////

public void execute(ScopedContext context, ITemplateRenderCallback callback) {
        // push a context first
        Object cursorPosition = context
                .pushSection(this.block.getSectionName());
        if (!context.isEmptyContext(cursorPosition)) {
            TemplateExecutor.execute(this.block.getStatements(), context,
                    callback);
            context.pop(); // leave as is
        } else {
                context.pop(); // add this line
            TemplateExecutor.execute(this.block.getStatements("or"), context,
                    callback);
        }
    }

////////////////////////////////////////////////////////

Original comment by isungu...@issart.com on 6 Mar 2012 at 7:31

GoogleCodeExporter commented 9 years ago

Original comment by isungu...@issart.com on 12 Mar 2012 at 8:40

GoogleCodeExporter commented 9 years ago

Original comment by isungu...@issart.com on 12 Mar 2012 at 9:46