IllegalStateException using your example

Using this example (this is the entire template and no data sources): <<var [s = “Hello!”]>><<[s]>>

From this article: https://docs.aspose.com/words/java/using-variables/

I receive this error:

  Error in ReportingEngine.buildReport() = > IllegalStateException: An error has been encountered at the end of expression 's]>'. Can not get the value of member 's' on type 'class [Ljava.lang.Object;'. = > java.lang.IllegalStateException: An error has been encountered at the end of expression 's]>'. Can not get the value of member 's' on type 'class [Ljava.lang.Object;'. 
	at com.aspose.words.internal.zzXzc.zzwE(Unknown Source) 
	at com.aspose.words.internal.zzXzc.zzwE(Unknown Source) 
	at com.aspose.words.internal.zzns.zzVP7(Unknown Source) 
	at com.aspose.words.internal.zzZua.zzWWr(Unknown Source) 
	at com.aspose.words.internal.zzZua.zzXmb(Unknown Source) 
	at com.aspose.words.internal.zzZua.zzWMB(Unknown Source) 
	at com.aspose.words.internal.zzns.zzwE(Unknown Source) 
	at com.aspose.words.internal.zzns.zzwE(Unknown Source) 
	at com.aspose.words.internal.zziP.zzwE(Unknown Source) 
	at com.aspose.words.internal.zziP.zzwE(Unknown Source) 
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source) 
	at com.aspose.words.ReportingEngine.buildReport(Unknown Source)

@rocketpower I cannot reproduce the problem on on my side. I have used the following simple code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("<<var [s = \"Hello!\"]>><<[s]>>");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, new Object());
doc.save("C:\\Temp\\out.docx");

Could you please share your template and code that will allow us to reproduce the problem? We will check the issue and provide you more information.

That sample works, but if I slightly modify it to not use DocumentBuilder, it fails with IllegalStateException. It’s note worthy that if the VAR is not specified, the report generation succeeds just fine. Here is the code sample that fails:

try
{
    ReportingEngine engine = new ReportingEngine();
    HtmlLoadOptions loadOptions = new HtmlLoadOptions(LoadFormat.HTML, "", "");
    String htmlTemplate = "<<var [s = \"Hello!\"]>><<[s]>>";
    InputStream targetStream = new ByteArrayInputStream(htmlTemplate.getBytes());
    Document doc = new Document(targetStream, loadOptions);

    List<Object> dataSources = new ArrayList<Object>();
    List<String> dataSourceNames = new ArrayList<String>();
    boolean result = engine.buildReport(doc, dataSources.toArray(), Arrays.toString(dataSourceNames.toArray()));
    if (result)
    {
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        doc.save(outputStream, saveOptions);

        String beforeDecoding = outputStream.toString(Charset.defaultCharset().toString());
        String retVal = StringEscapeUtils.unescapeHtml(StringEscapeUtils.unescapeJava(beforeDecoding));
        LogHelper.logs().log("Report Html Result=" + retVal);
        return retVal;
    }
}
catch (Exception e)
{
    LogHelper.logs().log(e);
    throw new InternalErrorException(e);
}

And here is the exception from the above code:

java.lang.IllegalStateException: An error has been encountered at the end of expression 's]>'. Can not get the value of member 's' on type 'class [Ljava.lang.Object;'. 	at com.aspose.words.internal.zzXzc.zzwE(Unknown Source) 	at com.aspose.words.internal.zzXzc.zzwE(Unknown Source) 	at com.aspose.words.internal.zzns.zzVP7(Unknown Source) 	at com.aspose.words.internal.zzZua.zzWWr(Unknown Source) 	at com.aspose.words.internal.zzZua.zzXmb(Unknown Source) 	at com.aspose.words.internal.zzZua.zzWMB(Unknown Source) 	at com.aspose.words.internal.zzns.zzwE(Unknown Source) 	at com.aspose.words.internal.zzns.zzwE(Unknown Source) 	at com.aspose.words.internal.zziP.zzwE(Unknown Source) 	at com.aspose.words.internal.zziP.zzwE(Unknown Source) 	at com.aspose.words.ReportingEngine.buildReport(Unknown Source) 	at com.aspose.words.ReportingEngine.buildReport(Unknown Source) 	```

@rocketpower The problem occurs because < and > characters should be escaped in HTML. Your htmlTemplate string should look like this to keep LINQ reporting syntax after importing HTML:

String htmlTemplate = "&lt;&lt;var [s = \"Hello!\"]&gt;&gt;&lt;&lt;[s]&gt;&gt;";

Thank you, that did the trick.

1 Like