3

Trying to include bunch of HTML is a SSP template, I've got the following exception:

Caused by: java.lang.IllegalArgumentException: null
at scala.tools.asm.ByteVector.putUTF8(ByteVector.java:213)
at scala.tools.asm.ClassWriter.newUTF8(ClassWriter.java:1092)
at scala.tools.asm.ClassWriter.newString(ClassWriter.java:1525)
at scala.tools.asm.ClassWriter.newConstItem(ClassWriter.java:1042)
at scala.tools.asm.MethodWriter.visitLdcInsn(MethodWriter.java:1134)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genConstant(GenASM.scala:1582)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.scala$tools$nsc$backend$jvm$GenASM$JPlainBuilder$$genInstr$1(GenASM.scala:2296)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2227)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2213)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.foreach(BasicBlocks.scala:195)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlock$1(GenASM.scala:2213)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlocks$1(GenASM.scala:2151)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genCode(GenASM.scala:2746)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1471)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1341)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.emitFor$1(GenASM.scala:198)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:204)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1486)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1481)
at scala.tools.nsc.Global$Run.compile(Global.scala:1582)
at org.fusesource.scalate.support.ScalaCompiler.compile(ScalaCompiler.scala:100)
at org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:757)

Looking at scala.tools.asm.ByteVector I've found the following:

    public ByteVector putUTF8(String s) {
    int charLength = s.length();
    if(charLength > '\uffff') {
        throw new IllegalArgumentException();
    } else { ....

If template size is more than 65536 bytes, it fails to compile this template. What one has to do to include large piece of plain HTML into a SSP template? Include seems only to work with template files. Should I manually load and output html files in templates? Are there any better ways?

Alexey Kalmykov
  • 1,958
  • 2
  • 15
  • 27

1 Answers1

2

It seems that it is an inherent limitation.

Workaround: manually read the file and output it into the template (yes, it is ugly but works):

<% include("header.ssp") %>

<%@ val book:Integer %>

<% val bookHtml = "./public/books/" + "book_" + book + ".html"%>
<% val source = scala.io.Source.fromFile(bookHtml)
val lines = try source.mkString finally source.close()
%>

${unescape(lines)}

<% include("footer.ssp") %>
Alexey Kalmykov
  • 1,958
  • 2
  • 15
  • 27
  • Yeap, with some debugging I see that is jvm limitation. Scalate templates are mostly string literals in generated classes. Limitation comes from; CONSTANT_Utf8_info { u1 tag; u2 length; u1 bytes[length]; } .. As a result we changed it to the Freemarker instead of Scalate :) – Fatih Donmez Sep 08 '16 at 04:34