private void doubleEncodedUtf8(Query query) {
        int singleCharacterTerms = countSingleCharacterUserTerms(query.getModel().getQueryTree());
        if (singleCharacterTerms <= 4) {
            return;
        }
        String userInput = query.getModel().getQueryString();
        ByteBuffer asOctets = ByteBuffer.allocate(userInput.length());
        boolean asciiOnly = true;
        for (int i = 0; i < userInput.length(); ++i) {
            char c = userInput.charAt(i);
            if (c > 255) {
                return; // not double (or more) encoded
            }
            if (c > 127) {
                asciiOnly = false;
            }
            asOctets.put((byte) c);
        }
        if (asciiOnly) {
            return;
        }
        asOctets.flip();
        CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
                                                                    .onUnmappableCharacter(CodingErrorAction.REPORT);
        // OK, unmappable character is sort of theoretical, but added to be explicit
        try {
            decoder.decode(asOctets);
        } catch (CharacterCodingException e) {
            return;
        }
        utfRejections.add();
        throw new IllegalInputException("The user input has been determined to be double encoded UTF-8."
                                        + " Please investigate whether this is a false positive.");
    }
Check whether the query tree seems to be "well formed". In other words, run heuristics against
the input data to see whether the query should sent to the search backend.

@author Steinar Knutsen
container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java