We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

LINQ Template exception on Java 16 and later

Dear Support,

I get following exception in LINQ Template: "Error! Can not resolve
method ‘getResourceAsStream’ on type ‘class c.v.s.b.g.DocumentGenerator’ running Spring Boot application
on Java 16 or 17.
On Java 15 it works like expected.

It seems like a bug, but could you please check?

Template:

<< doc [DocumentGenerator.getResourceAsStream("sub-document.docx")] -build -sourceStyles >>

DocumentGenerator class:

public class DocumentGenerator {
  public static InputStream getResourceAsStream(String path) throws IOException {
      final ClassPathResource classPathResource = new ClassPathResource(path);
      return classPathResource.getInputStream();
  }
}

Engine execution code:

Document doc = new Document(documentResourceStream);
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(DocumentGenerator.class);
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS + ReportBuildOptions.INLINE_ERROR_MESSAGES + ReportBuildOptions.REMOVE_EMPTY_PARAGRAPHS);
XmlDataSource dbConstants = new XmlDataSource(getResourceAsStream("doc.xml"));
if (engine.buildReport(doc, dbConstants)) {
    LOGGER.info("Document generated successfully!");
} else {
    LOGGER.error("Document generation failed! Please check the generated document for inlined error message!");
};

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.save(byteArrayOutputStream, SaveFormat.DOCX);
return byteArrayOutputStream.toByteArray();

Lib maven info:

<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>aspose-words</artifactId>
  <version>21.9</version>
  <classifier>jdk17</classifier>
</dependency>

@vova.k,

Please compress the following resources into ZIP format and attach the .zip file here for testing:

  • A simplified source Word DOCX document
  • Aspose.Words generated DOCX file showing the desired output (use Java 15 to produce expected document).
  • XML file containing the data
  • Please also create a standalone simplified Java Application (source code without compilation errors) that helps us to reproduce this exception on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.

As soon as you get these pieces of information ready, we will then start further investigation into your particular scenario and provide you more information.

Hello @awais.hafeez

below are 3 files:

  1. zipped Spring Boot application - contains all Java sources, incl. source Word template and subtemplate
  2. resultjava15.docx - result document generated with app running under java 15
  3. resultjava16or17.docx - result document generated with app running under java 16 or 17

How to reproduce :

  1. unzip the file
  2. install maven https://maven.apache.org/install.html
    2a. switch to java 11, as the application is written for java 11. Plus maven has to build the project using java 11.
  3. run command: mvn clean install
  4. switch to java 16 or java 17
  5. run command: java -jar target/aspose-java17demo-0.0.1-SNAPSHOT.jar
  6. open browser and run link: http://localhost:8080/doc
  7. Result: you get result doc.docx file with the error downloaded

aspose-java17demo.zip (27.8 KB)
resultjava15.docx (19.5 KB)
resultjava16or17.docx (19.7 KB)

@vova.k,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSJAVA-2659. We will further look into the details of this problem and will keep you updated here on the status of linked issue. We apologize for your inconvenience.

1 Like