<commit_before>package com.sequenceiq.it.cloudbreak.newway;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

import static com.sequenceiq.it.cloudbreak.newway.log.Log.log;

public class ProxyHandler<I> implements InvocationHandler {

    private final I original;

    private final GenericProxyExecutor executor;

    public ProxyHandler(I original, GenericProxyExecutor executor) {
        this.original = original;
        this.executor = executor;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {
        printArgs(method, args);
        method.setAccessible(true);
        return executor.exec(() -> method.invoke(original, args));
    }

    private void printArgs(Method method, Object[] args) {
        if (args != null) {
            String[] declaringClass = method.getDeclaringClass().toString().split(" ");
            String initLogMessage = declaringClass.length == 2
                    ? String.format("Method ['%s.%s'] called with args:%n", method.getDeclaringClass().toString().split(" ")[1], method.getName())
                    : String.format("Method ['%s'] called with args:%n", method.getName());
            log(initLogMessage);
            log(String.join(", ", Arrays.stream(args).map(Object::toString).collect(Collectors.toList())));
        }
    }
}<commit_msg>BUG-105888 – NPE on proxy method invocation when null parameter passed to it<commit_after>package com.sequenceiq.it.cloudbreak.newway;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

import static com.sequenceiq.it.cloudbreak.newway.log.Log.log;

public class ProxyHandler<I> implements InvocationHandler {

    private final I original;

    private final GenericProxyExecutor executor;

    public ProxyHandler(I original, GenericProxyExecutor executor) {
        this.original = original;
        this.executor = executor;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {
        printArgs(method, args);
        method.setAccessible(true);
        return executor.exec(() -> method.invoke(original, args));
    }

    private void printArgs(Method method, Object[] args) {
        if (args != null) {
            String[] declaringClass = method.getDeclaringClass().toString().split(" ");
            String initLogMessage = declaringClass.length == 2
                    ? String.format("Method ['%s.%s'] called with args:%n", method.getDeclaringClass().toString().split(" ")[1], method.getName())
                    : String.format("Method ['%s'] called with args:%n", method.getName());
            log(initLogMessage);
            log(String.join(", ", Arrays.stream(args).map(o -> o == null ? "null" : o.toString()).collect(Collectors.toList())));
        }
    }
}
{'fraction_non_alphanumeric': 0.131175468483816, 'fraction_numerical': 0.0034071550255536627, 'mean_word_length': 3.206303724928367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1223443', 'n_tokens_mistral': 816, 'n_tokens_neox': 791, 'n_words': 184}