简体   繁体   中英

Is it possible for for a runtimeexception to be thrown when assigning a null reference in Java?

I'm taking part in a reverse engineering challenge in Java, as I wanted to learn more about obfuscation outside of .NET land.

I have some deobfuscated source code, and my objective is to separate out the bloat from real code in a large application and answer a series of questions about the application.

I'm unfamiliar with Java, and am wondering if it's possible for this method to throw a runtimeexception during execution. I can't imagine that it is as the entirety of the method is just assigning things to null, but couldn't find anything about this online to confirm one way or the other.

public static void SomeMethod() {
    try {
        someObject_1 = null;
        someObject_2 = null;
        someObjectArray1 = null;
        intArray1 = null;
        shortArray1 = null;
        //...etc
    } catch (RuntimeException runtimeexception) {
        // Attempt at hiding stack traces when I break things I assume
        // These are littered everywhere, with a unique identifier
        // and arguments in the parentheses if method has args
        //
        throw SomeClass_SubClass_SubClass.someExceptionFactory(runtimeexception, "f.C()");
    }
}

Where someExceptionFactory wraps the thrown exception in a class that extends RuntimeException .

You should provide more information on the code you didn't show and the context. But assuming the only code inside the try block are null assignments to class fields (the variables are not declared inside the method body), the method itself will not throw a RuntimeException.

No, not possible, if the rest of the statements are assignments of null to variables.

No exception can be thrown by this code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM