Javascript ReferenceError: 'importPackage' is not defined - Identity Portal Nashorn Engine
search cancel

Javascript ReferenceError: 'importPackage' is not defined - Identity Portal Nashorn Engine

book

Article ID: 74733

calendar_today

Updated On:

Products

CA Identity Portal CA Identity Suite

Issue/Introduction

After upgrading Symantec Identity Portal to version 14.x, legacy JavaScript handlers may fail during execution.

This failure is typically due to the underlying JVM upgrade to Java 1.8, which replaced the "Rhino" JavaScript engine with the "Nashorn" engine. Nashorn does not support legacy Rhino functions like importPackage() by default.

Environment

Identity Portal 14.x

Cause

In Java 1.8, the default JavaScript engine changed from Rhino to Nashorn. Nashorn is strictly compliant with the ECMAScript specification and does not automatically include the Mozilla-specific compatibility extensions (like importPackage or importClass) that were available in Rhino.

Resolution

Option 1: Enable Mozilla Compatibility (Quick Fix)

To restore legacy support for importPackage, add the following line to the very top of your JavaScript handler:

load("nashorn:mozilla_compat.js");

Option 2: Use Modern Nashorn Syntax (Recommended)

Instead of importing entire packages, it is a best practice to use Java.type to reference specific Java classes. This improves performance and script clarity.

Example - Legacy Rhino Syntax:

importPackage(java.util);var list = new ArrayList();

Example - Modern Nashorn Syntax:

var ArrayList = Java.type("java.util.ArrayList");var list = new ArrayList();