<commit_before>package com.foomoo.awf.converters;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

@FacesConverter(value = "localDateConverter")
public class LocalDateConverter implements Converter {

    @Override
    public Object getAsObject(final FacesContext context, final UIComponent component, final String value) {
        try {
            return LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
        } catch (final DateTimeParseException dtpe) {
            try {
                return LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/M/yyyy"));
            } catch (final DateTimeParseException dtpe2) {
                throw new ConverterException(new FacesMessage("Cannot convert String " + value + " to date."));
            }
        }
    }

    @Override
    public String getAsString(final FacesContext context, final UIComponent component, final Object value) {
        final LocalDate localDate = (LocalDate) value;
        return localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
    }
}
<commit_msg>Detect empty dates in LocalDateConverter and return as null for handling by relevant page validators.<commit_after>package com.foomoo.awf.converters;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

@FacesConverter(value = "localDateConverter")
public class LocalDateConverter implements Converter {

    @Override
    public Object getAsObject(final FacesContext context, final UIComponent component, final String value) {
        if ("".equals(value)) {
            return null;
        }

        try {
            return LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
        } catch (final DateTimeParseException dtpe) {
            try {
                return LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/M/yyyy"));
            } catch (final DateTimeParseException dtpe2) {
                throw new ConverterException(new FacesMessage("Cannot convert String " + value + " to date."));
            }
        }
    }

    @Override
    public String getAsString(final FacesContext context, final UIComponent component, final Object value) {
        final LocalDate localDate = (LocalDate) value;
        return localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
    }
}

{'fraction_non_alphanumeric': 0.09032038173142468, 'fraction_numerical': 0.0006816632583503749, 'mean_word_length': 3.6003134796238245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6719733', 'n_tokens_mistral': 765, 'n_tokens_neox': 757, 'n_words': 184}