Repository: netty/netty
File: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java (Java)

Code before:
        apn = (OpenSslApplicationProtocolNegotiator) context.applicationProtocolNegotiator();
        clientMode = context.isClient();
        this.endpointIdentificationAlgorithm = endpointIdentificationAlgorithm;
        this.serverNames = serverNames;

        session = new ExtendedOpenSslSession(new DefaultOpenSslSession(context.sessionContext())) {
            private String[] peerSupportedSignatureAlgorithms;
            private List<SNIServerName> requestedServerNames;

            @Override
            public List<SNIServerName> getRequestedServerNames() {
                if (clientMode) {
                    List<SNIServerName> names = ReferenceCountedOpenSslEngine.this.serverNames;
                    return names == null ? Collections.emptyList() : Collections.unmodifiableList(names);
                } else {
                    synchronized (ReferenceCountedOpenSslEngine.this) {
                        if (requestedServerNames == null) {
                            if (destroyed) {
                                requestedServerNames = Collections.emptyList();
                            } else {
                                String name = SSL.getSniHostname(ssl);
                                requestedServerNames = (name == null || name.isEmpty()) ?
                                        Collections.emptyList() :
                                        Collections.singletonList(new SNIHostName(name.getBytes(CharsetUtil.UTF_8)));
                            }
                        }
                        return requestedServerNames;
                    }
                }
            }

            @Override
            public String[] getPeerSupportedSignatureAlgorithms() {
                synchronized (ReferenceCountedOpenSslEngine.this) {
                    if (peerSupportedSignatureAlgorithms == null) {
                        if (destroyed) {
                            peerSupportedSignatureAlgorithms = EMPTY_STRINGS;
                        } else {
                            String[] algs = SSL.getSigAlgs(ssl);
                            if (algs == null) {
                                peerSupportedSignatureAlgorithms = EMPTY_STRINGS;
                            } else {
                                Set<String> algorithmList = new LinkedHashSet<>(algs.length);
                                for (String alg: algs) {
                                    String converted = SignatureAlgorithmConverter.toJavaName(alg);

                                    if (converted != null) {
                                        algorithmList.add(converted);
                                    }
                                }
                                peerSupportedSignatureAlgorithms = algorithmList.toArray(EMPTY_STRINGS);

Review comment (suggestion):
```suggestion
                                        // Convert to bytes as we do not want to do any strict validation of the
                                        // SNIHostName while creating it.
                                        Collections.singletonList(new SNIHostName(name.getBytes(CharsetUtil.UTF_8)));
```

Code after:
        apn = (OpenSslApplicationProtocolNegotiator) context.applicationProtocolNegotiator();
        clientMode = context.isClient();
        this.endpointIdentificationAlgorithm = endpointIdentificationAlgorithm;
        this.serverNames = serverNames;

        session = new ExtendedOpenSslSession(new DefaultOpenSslSession(context.sessionContext())) {
            private String[] peerSupportedSignatureAlgorithms;
            private List<SNIServerName> requestedServerNames;

            @Override
            public List<SNIServerName> getRequestedServerNames() {
                if (clientMode) {
                    List<SNIServerName> names = ReferenceCountedOpenSslEngine.this.serverNames;
                    return names == null ? Collections.emptyList() : Collections.unmodifiableList(names);
                } else {
                    synchronized (ReferenceCountedOpenSslEngine.this) {
                        if (requestedServerNames == null) {
                            if (destroyed) {
                                requestedServerNames = Collections.emptyList();
                            } else {
                                String name = SSL.getSniHostname(ssl);
                                requestedServerNames = (name == null || name.isEmpty()) ?
                                        Collections.emptyList() :
                                        // Convert to bytes as we do not want to do any strict validation of the
                                        // SNIHostName while creating it.
                                        Collections.singletonList(new SNIHostName(name.getBytes(CharsetUtil.UTF_8)));
                            }
                        }
                        return requestedServerNames;
                    }
                }
            }

            @Override
            public String[] getPeerSupportedSignatureAlgorithms() {
                synchronized (ReferenceCountedOpenSslEngine.this) {
                    if (peerSupportedSignatureAlgorithms == null) {
                        if (destroyed) {
                            peerSupportedSignatureAlgorithms = EMPTY_STRINGS;
                        } else {
                            String[] algs = SSL.getSigAlgs(ssl);
                            if (algs == null) {
                                peerSupportedSignatureAlgorithms = EMPTY_STRINGS;
                            } else {
                                Set<String> algorithmList = new LinkedHashSet<>(algs.length);
                                for (String alg: algs) {
                                    String converted = SignatureAlgorithmConverter.toJavaName(alg);

                                    if (converted != null) {
                                        algorithmList.add(converted);
                                    }