Sidebar

Cannot call property getInstance in object [JavaPackage javax.mail.Session]

0 votes
59 views
asked Aug 26 by ben-s-7515 (12,850 points)
After upgrading QIE to the latest release, I have a script that stopped working.  Now it throws an exception:

TypeError: Cannot call property getInstance in object [JavaPackage javax.mail.Session]. It is not a function, it is "object". (<Unknown Source>#3)

What caused this and how do I fix it?

1 Answer

0 votes
 
Best answer

This is caused by libraries in QIE switching from the older javax packages to the new jakarta packages.  These changes were initiated in 2019 after Oracle open sourced Java EE, but retained the Java brand.  More information can be found on this stackoverflow.

As Qvera updates the engine, we are required to switch from the javax packages to jakarta.  This is a breaking change for any custom scripts that are using the javax packages.  However, the fix to this error is simple, but does required the channel to be updated.  We can fix the script by replacing all instances of 'javax.' in the code with 'Packages.jakarta.'.  For exmple, to fix this script

var props = new java.util.Properties();
var session = javax.mail.Session.getInstance(props, null);
var mimeMessage = new javax.mail.internet.MimeMessage(session);

we will replace it with this

var props = new java.util.Properties();
var session = Packages.jakarta.mail.Session.getInstance(props, null);
var mimeMessage = new Packages.jakarta.mail.internet.MimeMessage(session);

Once the references to javax are replaced with Packages.jakarta, you will be able to save the channel and restart it.  The process should start working as designed.

answered Aug 26 by ben-s-7515 (12,850 points)
selected Aug 26 by jon-t-7005
...