Troubleshooting
Problem
When JAR files are loaded in WebSphere Application Server by the classloader, either from an application or internally, the order of the JAR files returned may not be the same on all systems.
Cause
Files are made available from the underlying file system using the java.io.File.listFiles() method. In turn, this method relies on the order returned by the corresponding native method on the operating system where the application server is running.
Typically the order of the files differs by platform and filesystem type, but can also be different on multiple systems running the same versions of each. This behavior is documented in the Sun Java 8 Javadoc for listFiles(), but also applies to the IBM SDK version of listFiles() as well:
Typically the order of the files differs by platform and filesystem type, but can also be different on multiple systems running the same versions of each. This behavior is documented in the Sun Java 8 Javadoc for listFiles(), but also applies to the IBM SDK version of listFiles() as well:
- "There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order. "
Diagnosing The Problem
The following Java code provides an example of how to print the directory order using the java.io.File.listFiles method. As a comparison, the code could be run on the different systems to see if the order returned from the OS changes:
import java.io.File; public class ListFilesTest { public static void main(String[] args) { String dir = ""; if(args.length == 1) { dir = args[0]; } else { System.out.println("Usage: java ListFilesTest <directory>"); System.exit(0); } File directory = new File(dir); if ( !directory.exists() ) { System.out.println("Error: Directory does not exist"); System.exit(0); } File[] files = directory.listFiles(); if (files!=null) { for (int i=0; i<files.length; i++) { File f = files[i]; System.out.println(f.getName()); } } } } |
Resolving The Problem
As a best practice, the order of the JAR files returned by listFiles() should not be relied upon to prevent problems as the application is moved to different systems.
[{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"ARM Category":[{"code":"a8m50000000Cd5cAAC","label":"WebSphere Application Server traditional-All Platforms-\u003EClassloader-\u003EClassloader: Best Practices-Common Issues"}],"ARM Case Number":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"8.5.0;8.5.5;9.0.0;9.0.5"}]
Was this topic helpful?
Document Information
Modified date:
04 November 2022
UID
swg21428892