Multithreading issue "Item has already been added."

Aspose libs should be thread safe as long as a doument is accessed only in one thread - shouldn’t they?

The following example code and documents lead to exceptions like:

class com.aspose.cad.cadexceptions.ImageLoadException: Image loading failed: Item has already been added. Key in dictionary: '44'  Key being added: '44' ---> class com.aspose.cad.internal.Exceptions.ArgumentException: Item has already been added. Key in dictionary: '44'  Key being added: '44'
com.aspose.cad.internal.O.k.a(Unknown Source)
com.aspose.cad.internal.O.k.b(Unknown Source)
com.aspose.cad.internal.gA.n.<init>(Unknown Source)
com.aspose.cad.internal.gA.j.<init>(Unknown Source)
com.aspose.cad.internal.gA.k.<init>(Unknown Source)
com.aspose.cad.internal.gA.l.<init>(Unknown Source)
com.aspose.cad.internal.gA.n.b(Unknown Source)
com.aspose.cad.internal.gA.bL.a(Unknown Source)
com.aspose.cad.internal.gA.bJ.load(Unknown Source)
com.aspose.cad.Image.a(Unknown Source)
com.aspose.cad.Image.a(Unknown Source)
com.aspose.cad.Image.f(Unknown Source)
com.aspose.cad.Image.load(Unknown Source)

Example documents:

Downloads.zip (886.3 KB)

Example program, uses aspose-cad:23.7

  public static void main(String[] args) throws IOException, InterruptedException {
    File dwg = new File("../test-resources/dwg", "2021-10-05_Regeldetails_Sanitär_VH.dwg");
    File dxf = new File("../test-resources/dwg", "obj 2086.dxf");

    int count = 10;
    CountDownLatch cdl = new CountDownLatch(count * 2);
    
    for (int i = 0; i < count; i++) {
      new Thread(() -> convert(dwg, cdl)).start();
      new Thread(() -> convert(dxf, cdl)).start();
    }
    
    cdl.await();
    System.out.println("done");
  }

  private static void convert(File inFile, CountDownLatch cdl) {
    File outFile = new File(inFile.getParent(), inFile.getName() + ".out");
    try (InputStream istream = new FileInputStream(inFile);
        OutputStream ostream = new FileOutputStream(outFile);
        com.aspose.cad.Image image = com.aspose.cad.Image.load(istream)) {

      CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
      rasterizationOptions.setPageWidth(1600);
      rasterizationOptions.setPageHeight(1600);

      PdfOptions opts = new PdfOptions();
      opts.setVectorRasterizationOptions(rasterizationOptions);

      image.save(ostream, opts);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      cdl.countDown();
    }
  }

@wimix
Thank you for all the details provided, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CADJAVA-11339

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.