<commit_before>/*
 * Copyright 2016-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.stream.config;

import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.SmartMessageConverter;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
import org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;

/**
 * @author <NAME>
 * @deprecated will be removed once https://jira.spring.io/browse/SPR-17503 is addressed
 */
@Deprecated
class SmartPayloadArgumentResolver extends PayloadArgumentResolver {

	private final MessageConverter messageConverter;

	SmartPayloadArgumentResolver(MessageConverter messageConverter) {
		super(messageConverter);
		this.messageConverter = messageConverter;
	}

	SmartPayloadArgumentResolver(MessageConverter messageConverter, Validator validator) {
		super(messageConverter, validator, true);
		this.messageConverter = messageConverter;
	}

	SmartPayloadArgumentResolver(MessageConverter messageConverter, Validator validator,
			boolean useDefaultResolution) {
		super(messageConverter, validator, useDefaultResolution);
		this.messageConverter = messageConverter;
	}

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return (!Message.class.isAssignableFrom(parameter.getParameterType())
				&& !MessageHeaders.class.isAssignableFrom(parameter.getParameterType())
				&& !parameter.hasParameterAnnotation(Header.class)
				&& !parameter.hasParameterAnnotation(Headers.class));
	}

	@Override
	@Nullable
	public Object resolveArgument(MethodParameter parameter, Message<?> message)
			throws Exception {
		Payload ann = parameter.getParameterAnnotation(Payload.class);
		if (ann != null && StringUtils.hasText(ann.expression())) {
			throw new IllegalStateException(
					"@Payload SpEL expressions not supported by this resolver");
		}

		Object payload = message.getPayload();
		if (isEmptyPayload(payload)) {<commit_msg>Support KafkaNull in payload conversion<commit_after>/*
 * Copyright 2016-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.stream.config;

import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.SmartMessageConverter;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
import org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;

/**
 * @author <NAME>
 * @author <NAME>
 * @deprecated will be removed once https://jira.spring.io/browse/SPR-17503 is addressed
 * (but see note about KafkaNull below).
 */
@Deprecated
class SmartPayloadArgumentResolver extends PayloadArgumentResolver {

	private final MessageConverter messageConverter;

	SmartPayloadArgumentResolver(MessageConverter messageConverter) {
		super(messageConverter);
		this.messageConverter = messageConverter;
	}

	SmartPayloadArgumentResolver(MessageConverter messageConverter, Validator validator) {
		super(messageConverter, validator, true);
		this.messageConverter = messageConverter;
	}

	SmartPayloadArgumentResolver(MessageConverter messageConverter, Validator validator,
			boolean useDefaultResolution) {
		super(messageConverter, validator, useDefaultResolution);
		this.messageConverter = messageConverter;
	}

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return (!Message.class.isAssignableFrom(parameter.getParameterType())
				&& !MessageHeaders.class.isAssignableFrom(parameter.getParameterType())
				&& !parameter.hasParameterAnnotation(Header.class)
				&& !parameter.hasParameterAnnotation(Headers.class));
	}

	/**
	 * Needed to support mapping KafkaNull to null in method invocation.
	 */
	@Override
	protected boolean isEmptyPayload(Object payload) {
		return super.isEmptyPayload(payload)
				|| "org.springframework.kafka.support.KafkaNull"
						.equals(payload.getClass().getName());
	}

	@Override
	@Nullable
	public Object resolveArgument(MethodParameter parameter, Message<?> message)
			throws Exception {
		Payload ann = parameter.getParameterAnnotation(Payload.class);
		if (ann != null && StringUtils.hasText(ann.expression())) {
			throw new IllegalStateException(
					"@Payload SpEL expressions not supported by this resolver");
		}

		Object payload = message.getPayload();
		if (isEmptyPayload(payload)) {
{'fraction_non_alphanumeric': 0.08548820121520419, 'fraction_numerical': 0.004804295605482549, 'mean_word_length': 6.085085085085085, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4159999', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1706, 'n_words': 453}