During vsd->vsdx file conversion, null pointer exception is thrown.
vsd file and callstack:
2023.05.26.zip (7.9 MB)
The file was converted using this code:
File file = new File(PATH_TO_VSD_FILE);
Diagram d = new Diagram(file.getAbsolutePath());
d.save(file.getAbsolutePath() + "x", SaveFileFormat.VSDX);
@casserolepan
Summary
You get a NullPointerException when trying to convert a Visio .vsd file to .vsdx with Aspose.Diagram for Java using:
File file = new File(PATH_TO_VSD_FILE);
Diagram d = new Diagram(file.getAbsolutePath());
d.save(file.getAbsolutePath() + "x", SaveFileFormat.VSDX);
The exception is thrown inside the Diagram.save call.
Why it happens
The most common reasons for an NPE in this scenario are:
- Invalid file path –
file.getAbsolutePath() returns a string that does not point to an existing file (e.g., the file is missing, the path contains illegal characters, or the program does not have read permission). When the constructor tries to load the document it receives a null stream, which later leads to an NPE.
- Incorrect output file name – appending
"x" to the original path creates a name like C:\folder\myfile.vsdx without a separator (the original name already ends with .vsd). If the original path already ends with .vsd, the resulting string becomes myfile.vsdx (which is fine), but if the original path does not end with a separator, the generated path may be malformed (e.g., C:\folder\myfile.vsdx is okay, but C:\folder\myfile.vsdx when the original string already contains an extension can confuse the loader). Using an explicit output file name removes this ambiguity.
- Bug in older Aspose.Diagram versions – some early 2023 releases had a known bug that caused an NPE when the source Visio file contained certain shapes or when the layout engine was invoked automatically during save. The bug was fixed in later releases (e.g., 23.9 and newer).
- Missing license – when running the library without a valid license, some internal objects are not initialised, which can also surface as an NPE in certain code paths.
What to do next
- Validate the input file
File file = new File(PATH_TO_VSD_FILE);
if (!file.exists()) {
throw new IllegalArgumentException("Visio file not found: " + file.getAbsolutePath());
}
- Use an explicit output path (do not rely on string concatenation of the original path):
String outPath = PATH_TO_VSD_FILE + ".vsdx"; // or any folder you prefer
Diagram d = new Diagram(file.getAbsolutePath());
d.save(outPath, SaveFileFormat.VSDX);
- Upgrade Aspose.Diagram to the latest version (at least 23.9 or newer). The NPE on certain VSD files was resolved in those releases.
- Apply a license (if you have one) before creating the
Diagram object:
License lic = new License();
lic.setLicense("Aspose.Diagram.Java.lic");
- Disable automatic layout refresh (a workaround for the bug) if upgrading is not possible:
SaveOptions options = new VsdxSaveOptions();
((VsdxSaveOptions)options).setRefreshLayout(false);
d.save(outPath, options);
- Capture the full stack trace and, if the problem persists, open a support ticket with Aspose. Attach the problematic VSD file, the exact version of the library, and the stack trace – this will allow the support team to reproduce the issue quickly.
By confirming the file exists, providing a clean output path, using a recent library version, and optionally disabling layout refresh, the NullPointerException should be eliminated.
If after these steps the exception is still thrown, please share the complete stack trace and the exact Aspose.Diagram for Java version you are using so we can investigate further.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
SDK version unclear — refer to the official release notes before applying this guidance.
@casserolepan
Thanks for the template file.
I have tested your scenario/case using our latest version : Aspose.Diagram for Java v25.11 . It works fine and as expected.
Please find attached the output vsdx file for your reference.
2023.05.26.zip (6.7 MB)
As you can see it works fine with latest version and we could not find any issue, so kindly use latest version. If you still find the issue with latest version, then please share your working environment e.g. operating system, Java version, project type that you are using?We will evaluate your issue further.
The error is indeed gone when converting with the latest version. Thank you, and sorry for the inconvenience!
@casserolepan
It is great that you were able to resolve this issue on your end. In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Diagram’ forum.