Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-9897

getBytes(); calls should be replaced with getBytes(StandardCharsets.UTF_8);

    Details

      Description

      There are several calls of method getBytes(); in clustering subsystem. These calls were identified by Coverity static code analysis as dubious [1]. getBytes() depends on platform's default charset [2]. This will cause the application behaviour to vary between platforms.

      Better solution would imho be getBytes(StandardCharsets.UTF_8);

      Occurrences:

      ./jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/DigestAuthTokenBuilder.java:60:            return new BinaryAuthToken(digest.digest(sharedSecret.getBytes()));
      ./jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/PlainAuthTokenBuilder.java:39:        return new BinaryAuthToken(sharedSecret.getBytes());
      ./jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/CipherAuthTokenBuilder.java:105:            return new CipherAuthToken(cipher, pair, authValue.getBytes());
      ./marshalling/jboss/src/test/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValueFactoryTestCase.java:93:        assertNull(mv.getBytes());
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/HashableMarshalledValueExternalizer.java:50:        return new HashableMarshalledValue<>(value.getBytes(), hashCode);
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValue.java:67:    byte[] getBytes() throws IOException {
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValue.java:135:            byte[] us = this.getBytes();
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValue.java:136:            byte[] them = value.getBytes();
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValue.java:152:        byte[] bytes = this.getBytes();
      ./marshalling/jboss/src/main/java/org/wildfly/clustering/marshalling/jboss/SimpleMarshalledValueExternalizer.java:51:        byte[] bytes = object.getBytes();
      

      [1] http://station5.brq.redhat.com:8080/docs/en/findbugs/fb_checker_ref.html#FB.DM_DEFAULT_ENCODING
      [2] https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#getBytes--

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                treblereel Dmitrii Tikhomirov
                Reporter:
                mvinkler Michal Vinkler
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: