Error Reference

Illegal access to Java package: access denied

Illegal access to Java package: access denied

Where this appears

This error appears in the System Log under System Diagnostics > Log > Application Log when server-side JavaScript attempts to import or instantiate Java classes. It commonly occurs during execution of Business Rules, Script Includes, Scheduled Jobs, or other server-side scripts that try to access restricted Java packages.

Sourdough
Chrome Extension

Debugging this in a real instance?

Sourdough lets you trace "Illegal access to Java package: access denied" through system logs, script errors, and API health in the ServiceNow tab you are already using.

Add to Chrome

Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.

Overview
Tasks
CMDB
API
Metrics
Monitor
Internals
Instance:sourdoughdev·Version:Yokohama
Instance StateONLINE
System StatusFully Operational
Session Timeout90 minutes
Logged-In Sessions2 (20 active)
Build Nameyokohama-12-18-2024_p1
IP Address10.159.128.43
Instance HealthHealth Score: 90%
🔥 5dSourdough (Chrome Plugin)Dark Mode

Cause

Script is attempting to access Java classes not included in ServiceNow's allowlist of permitted Java packages for security reasons. (high likelihood)

Code migrated from older ServiceNow versions that previously allowed broader Java access before security restrictions were tightened. (high likelihood)

Developer is trying to use standard Java libraries like java.io, java.net, or java.util classes that are blocked in scoped applications. (medium likelihood)

Script contains typos in Java class names that resolve to restricted packages instead of intended ServiceNow APIs. (medium likelihood)

Third-party code or examples copied from external sources that assume unrestricted Java access in ServiceNow environment. (low likelihood)

Fix

Step 1: Navigate to System Diagnostics > Log > Application Log and locate the specific error entry to identify which Java class or package is being accessed.

Step 2: Review the script causing the error and identify all Java class imports or instantiations, looking for patterns like 'new java.', 'Packages.java.', or 'java.lang.'.

Step 3: Check ServiceNow documentation for approved Java classes by searching 'Java API' in the product documentation or reviewing the Script Debugger allowed classes.

Step 4: Replace restricted Java classes with ServiceNow-native APIs such as GlideSystem, GlideRecord, GlideDateTime, or other Glide classes that provide similar functionality.

Step 5: For date/time operations, use GlideDateTime instead of java.util.Date; for string operations, use standard JavaScript instead of Java String methods.

Step 6: If Java functionality is absolutely required, consider implementing the logic in a MID Server script or external integration that can communicate back to ServiceNow via REST APIs.

Step 7: Test the modified script in a development instance and verify the error no longer appears in the System Log.

Step 8: Document the changes made for future reference and update any related code that might have similar Java access patterns.

Test Your Knowledge

Quick 3-question quiz. See how your ServiceNow skills stack up.

Question 1 of 3Performance

A list view on a table with millions of records is slow. Best fix?

Select an answer to continue