Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“NullPointerException”The number passed in the api is min() and max() is a null pointer. #2783

Open
Cici-Musse-Lee opened this issue May 31, 2022 · 0 comments

Comments

@Cici-Musse-Lee
Copy link

Cici-Musse-Lee commented May 31, 2022

The file path is org.zkoss.lang.Comparables.
In our test case, we pass compare0 and compare1 into the functions whose api is max() and min(). Inside these api, an exception occurs when a null pointer is referenced for comparison

source code:

@SuppressWarnings ("unchecked")
public static final Comparable min (Comparable a,Comparable b){
        return (a.compareTo(b)<0)?a b;
}


@SuppressWarnings("unchecked")
public static final Comparable max (Comparable a,Comparable b){
        return (a.compareTo(b)<0)?b : a;
}

test code:

@Test
public void test _min_5_5() throws NoSuchFieldException, IllegalAccessException{

        java.lang.Comparable<java.lang.object>comparable0=null;
        java.lang.Comparable<java.lang.Object>comparable1=null;
        org.zkoss.lang.Comparables.min(comparable0,comparable1);

}

@Test
public void test _max_1_6() throws NoSuchFieldException,IllegalAccessException{
        java.lang.Comparable<java.lang.Object>comparable0=null;
        java.lang.Comparable<java.lang.Object>comparable1=null;
        org.zkoss.lang.Comparables.max (comparable0,comparable1);

test results:

java.lang.NullPointerException:Cannot invoke "java.lang.Comparable.compareTo(Object)"because "a"is null
at org.zkoss.lang.Comparables.min(Comparables.java:33)
at org.zkoss.lang.Comparables_Test.test_min_1_1(Comparables_Test.java:13)

@Cici-Musse-Lee Cici-Musse-Lee changed the title “NullPointerException”The number passed in the api is min() is a null pointer. “NullPointerException”The number passed in the api is min() and max() is a null pointer. May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant