I have decompiled a fix provided by a 3rd party development team.
This is the original code:
if (this.getPassword() != null) { this.uid = this.getUserName(); password = this.getPassword(); } if (this.host != null) { en.put("hostname", this.host); if (password != null && password.toString().trim().length() != 0) { en.put("password", password.toString()); } if (this.uid != null && this.uid.trim().length() != 0) { en.put("userID", this.uid); } } and this is the fix:
if (this.getPassword() != null) { this.uid = this.getUserName(); final char[] passwordTemp = this.getPassword(); password = new char[passwordTemp.length]; for (int i = 0; i < passwordTemp.length; ++i) { password[i] = passwordTemp[i]; } } if (this.host != null) { en.put("hostname", this.host); if (password != null && password.toString().trim().length() != 0) { en.put("password", new String(password)); } if (this.uid != null && this.uid.trim().length() != 0) { en.put("userID", this.uid); } } This seems to have significantly degraded the performance of the code. Does anyone know why this would be done? and is there a better way to do this?
char[]instead ofStringfor passwords. However, their implementation is very poor, as the password is still converted to string later :))this.getPassword()are erased at some point, while it is still needed elsewhere. Therefore they copy the password to a different array that wont be destroyed.passwordischar[]then callingtoStringon it is quite pointless, you won't get String representation of characters in the array.