Code Portability problems

Call to System.exit or Runtime.halt

Using these methods to communicate successful return status constitutes a dependency on the underlying operating system. Sometimes these calls are used when a fatal error is detected, which makes problems extremely hard to track down.

Solution: avoid these calls, if possible, by using assert or throwing an exception.

Severity level: 2

Operating System specific methods

The methods System.getenv() and Runtime.exec() introduce dependencies on the operating system and its configuration. For example, a program used by Runtime.exec() may not even exist on a different platform, or may exist in a different version with potentially different parameters. Similarly, environment variables accessed by System.getenv() may or may not exist, and their values may be operating system dependent (e.g. file paths), or may or may not be case sensitive.

Solution: carefully evaluate if these calls are really necessary

Severity level: 4

Hardcoded newline characters

The character sequence for a new line is operating system specific. The characters \r and \n in string and character literals should therefore be avoided in favor of using System.getProperty("line.separator") to ensure portability across operating systems.

Solution: use System.getProperty("line.separator")

Severity level: 5