IllegalArgumentException Args must not be null – Application run failed

In the Java application, the main method accepts command line arguments as string arrays. The string array may be either an empty array or a number of arguments. If the array is set to null, then this error is thrown from the application



Exception

ERROR org.springframework.boot.SpringApplication - Application run failed
 java.lang.IllegalArgumentException: Args must not be null
     at org.springframework.util.Assert.notNull(Assert.java:198)
     at org.springframework.boot.DefaultApplicationArguments.(DefaultApplicationArguments.java:41)
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
     at com.yawintutor.SpringHelloWorldApplication.main(SpringHelloWorldApplication.java:11)


Error Code

In the below example, value of the argument is set as null

package com.yawintutor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringHelloWorldApplication {
    public static void main(String[] args) {
        args = null;
        SpringApplication.run(SpringHelloWorldApplication.class, args);
    }
}


Root Cause

Spring boot application can not accept null as argument. Spring boot application accepts a string array as argument.



Solution

The spring boot arguments may be either an empty array or a number of arguments. If the argument is null, then set as an empty string array

package com.yawintutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringHelloWorldApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringHelloWorldApplication.class, args);
	}

}

How to create simple Spring Boot Application with Main method



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *