Add a warning for when targeting attributes are truncated by AntoxaAntoxic · Pull Request #4188 · prebid/prebid-server-java

    private Map<String, String> truncateKeys(Map<String, String> keyValues,
                                             Map<String, List<ExtBidderError>> bidWarnings) {

        if (truncateAttrChars <= 0) {
            return keyValues;
        }

        final Map<String, String> keys = new HashMap<>();
        final Set<String> truncatedKeys = new HashSet<>();
        for (Map.Entry<String, String> entry : keyValues.entrySet()) {
            final String key = entry.getKey();
            final String truncatedKey = truncateKey(key);
            keys.putIfAbsent(truncatedKey, entry.getValue());

            if (truncatedKey.length() != key.length()) {
                truncatedKeys.add(truncatedKey);
            }
        }

        if (!truncatedKeys.isEmpty()) {
            final String errorMessage = "The following keys have been truncated: %s"
                    .formatted(String.join(", ", truncatedKeys));
            bidWarnings.computeIfAbsent("targeting", ignored -> new ArrayList<>())
                    .add(ExtBidderError.of(BidderError.Type.bad_input.getCode(), errorMessage));
        }

        return keys;
    }

    private String truncateKey(String key) {
        return key.length() > truncateAttrChars
                ? key.substring(0, truncateAttrChars)
                : key;
    }