8074657: Missing space on a boundary of concatenated strings

Added missing spaces, fixed indentation, replaced StringBuffer with StringBuilder

Reviewed-by: martin, rriggs
This commit is contained in:
Ivan Gerasimov 2015-05-15 22:09:49 +03:00
parent 608c2ef496
commit ff06dffa94
2 changed files with 257 additions and 235 deletions

View File

@ -62,8 +62,8 @@ class WindowsPreferences extends AbstractPreferences {
/**
* Windows registry path to <tt>Preferences</tt>'s root nodes.
*/
private static final byte[] WINDOWS_ROOT_PATH
= stringToByteArray("Software\\JavaSoft\\Prefs");
private static final byte[] WINDOWS_ROOT_PATH =
stringToByteArray("Software\\JavaSoft\\Prefs");
/**
* Windows handles to <tt>HKEY_CURRENT_USER</tt> and
@ -404,8 +404,8 @@ class WindowsPreferences extends AbstractPreferences {
int[] result =
WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
if (result[ERROR_CODE] != ERROR_SUCCESS) {
logger().warning("Could not create windows registry "
+ "node " + byteArrayToString(windowsAbsolutePath()) +
logger().warning("Could not create windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegCreateKeyEx(...) returned error code " +
result[ERROR_CODE] + ".");
@ -431,8 +431,8 @@ class WindowsPreferences extends AbstractPreferences {
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
logger().warning("Could not open/create prefs root node " +
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
Integer.toHexString(rootNativeHandle()) +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegCreateKeyEx(...) returned error code " +
result[ERROR_CODE] + ".");
isBackingStoreAvailable = false;
@ -512,16 +512,19 @@ class WindowsPreferences extends AbstractPreferences {
windowsAbsolutePath, mask2);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
logger().warning("Could not open windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
logger().warning("Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegOpenKey(...) returned error code " +
result[ERROR_CODE] + ".");
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED) {
throw new SecurityException("Could not open windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
throw new SecurityException(
"Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
": Access denied");
}
}
@ -555,8 +558,8 @@ class WindowsPreferences extends AbstractPreferences {
windowsRelativePath, mask2);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
logger().warning("Could not open windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
logger().warning("Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(nativeHandle) +
". Windows RegOpenKey(...) returned error code " +
result[ERROR_CODE] + ".");
@ -604,10 +607,12 @@ class WindowsPreferences extends AbstractPreferences {
private void closeKey(int nativeHandle) {
int result = WindowsRegCloseKey(nativeHandle);
if (result != ERROR_SUCCESS) {
logger().warning("Could not close windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegCloseKey(...) returned error code " + result + ".");
logger().warning("Could not close windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegCloseKey(...) returned error code " +
result + ".");
}
}
@ -627,10 +632,13 @@ class WindowsPreferences extends AbstractPreferences {
toWindowsName(javaName), toWindowsValueString(value));
if (result != ERROR_SUCCESS) {
logger().warning("Could not assign value to key " +
byteArrayToString(toWindowsName(javaName))+ " at Windows registry node "
+ byteArrayToString(windowsAbsolutePath()) + " at root 0x"
+ Integer.toHexString(rootNativeHandle()) +
". Windows RegSetValueEx(...) returned error code " + result + ".");
byteArrayToString(toWindowsName(javaName)) +
" at Windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegSetValueEx(...) returned error code " +
result + ".");
isBackingStoreAvailable = false;
}
closeKey(nativeHandle);
@ -672,8 +680,8 @@ class WindowsPreferences extends AbstractPreferences {
int result =
WindowsRegDeleteValue(nativeHandle, toWindowsName(key));
if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
logger().warning("Could not delete windows registry "
+ "value " + byteArrayToString(windowsAbsolutePath())+ "\\" +
logger().warning("Could not delete windows registry value " +
byteArrayToString(windowsAbsolutePath()) + "\\" +
toWindowsName(key) + " at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegDeleteValue(...) returned error code " +
@ -693,15 +701,18 @@ class WindowsPreferences extends AbstractPreferences {
// Find out the number of values
int nativeHandle = openKey(KEY_QUERY_VALUE);
if (nativeHandle == NULL_NATIVE_HANDLE) {
throw new BackingStoreException("Could not open windows"
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
throw new BackingStoreException(
"Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) + ".");
}
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
String info = "Could not query windows"
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
String info = "Could not query windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegQueryInfoKeyEx(...) returned error code " +
result[ERROR_CODE] + ".";
logger().warning(info);
@ -742,15 +753,17 @@ class WindowsPreferences extends AbstractPreferences {
// Open key
int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE);
if (nativeHandle == NULL_NATIVE_HANDLE) {
throw new BackingStoreException("Could not open windows"
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
throw new BackingStoreException(
"Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) + ".");
}
// Get number of children
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
String info = "Could not query windows"
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
String info = "Could not query windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegQueryInfoKeyEx(...) returned error code " +
result[ERROR_CODE] + ".";
@ -802,16 +815,20 @@ class WindowsPreferences extends AbstractPreferences {
}
int nativeHandle = openKey(KEY_READ);
if (nativeHandle == NULL_NATIVE_HANDLE) {
throw new BackingStoreException("Could not open windows"
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
throw new BackingStoreException(
"Could not open windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) + ".");
}
int result = WindowsRegFlushKey1(nativeHandle);
if (result != ERROR_SUCCESS) {
String info = "Could not flush windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath())
+ " at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegFlushKey(...) returned error code " + result + ".";
String info = "Could not flush windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) +
". Windows RegFlushKey(...) returned error code " +
result + ".";
logger().warning(info);
throw new BackingStoreException(info);
}
@ -851,15 +868,17 @@ class WindowsPreferences extends AbstractPreferences {
int parentNativeHandle =
((WindowsPreferences)parent()).openKey(DELETE);
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
throw new BackingStoreException("Could not open parent windows"
+ "registry node of " + byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) + ".");
throw new BackingStoreException(
"Could not open parent windows registry node of " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" +
Integer.toHexString(rootNativeHandle()) + ".");
}
int result =
WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
if (result != ERROR_SUCCESS) {
String info = "Could not delete windows "
+ "registry node " + byteArrayToString(windowsAbsolutePath()) +
String info = "Could not delete windows registry node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegDeleteKeyEx(...) returned error code " +
result + ".";
@ -883,17 +902,19 @@ class WindowsPreferences extends AbstractPreferences {
(windowsName.substring(0, 2).equals("/!"))) {
return toJavaAlt64Name(windowsName);
}
StringBuffer javaName = new StringBuffer();
StringBuilder javaName = new StringBuilder();
char ch;
// Decode from simple encoding
for (int i = 0; i < windowsName.length(); i++) {
if ((ch = windowsName.charAt(i)) == '/') {
char next = ' ';
if ((windowsName.length() > i + 1) &&
((next = windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
((next = windowsName.charAt(i+1)) >= 'A') &&
(next <= 'Z')) {
ch = next;
i++;
} else if ((windowsName.length() > i + 1) && (next == '/')) {
} else if ((windowsName.length() > i + 1) &&
(next == '/')) {
ch = '\\';
i++;
}
@ -915,7 +936,7 @@ class WindowsPreferences extends AbstractPreferences {
private static String toJavaAlt64Name(String windowsName) {
byte[] byteBuffer =
Base64.altBase64ToByteArray(windowsName.substring(2));
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (int i = 0; i < byteBuffer.length; i++) {
int firstbyte = (byteBuffer[i++] & 0xff);
int secondbyte = (byteBuffer[i] & 0xff);
@ -945,7 +966,7 @@ class WindowsPreferences extends AbstractPreferences {
* Base64 class.
*/
private static byte[] toWindowsName(String javaName) {
StringBuffer windowsName = new StringBuffer();
StringBuilder windowsName = new StringBuilder();
for (int i = 0; i < javaName.length(); i++) {
char ch = javaName.charAt(i);
if ((ch < 0x0020) || (ch > 0x007f)) {
@ -957,7 +978,7 @@ class WindowsPreferences extends AbstractPreferences {
} else if (ch == '/') {
windowsName.append('\\');
} else if ((ch >= 'A') && (ch <='Z')) {
windowsName.append("/" + ch);
windowsName.append('/').append(ch);
} else {
windowsName.append(ch);
}
@ -981,8 +1002,8 @@ class WindowsPreferences extends AbstractPreferences {
javaNameArray[counter++] = (byte)ch;
}
return stringToByteArray(
"/!" + Base64.byteArrayToAltBase64(javaNameArray));
return stringToByteArray("/!" +
Base64.byteArrayToAltBase64(javaNameArray));
}
/**
@ -994,7 +1015,7 @@ class WindowsPreferences extends AbstractPreferences {
private static String toJavaValueString(byte[] windowsNameArray) {
// Use modified native2ascii algorithm
String windowsName = byteArrayToString(windowsNameArray);
StringBuffer javaName = new StringBuffer();
StringBuilder javaName = new StringBuilder();
char ch;
for (int i = 0; i < windowsName.length(); i++){
if ((ch = windowsName.charAt(i)) == '/') {
@ -1005,13 +1026,14 @@ class WindowsPreferences extends AbstractPreferences {
if (windowsName.length() < i + 6) {
break;
} else {
ch = (char)Integer.parseInt
(windowsName.substring(i + 2, i + 6), 16);
ch = (char)Integer.parseInt(
windowsName.substring(i + 2, i + 6), 16);
i += 5;
}
} else
if ((windowsName.length() > i + 1) &&
((windowsName.charAt(i+1)) >= 'A') && (next <= 'Z')) {
((windowsName.charAt(i+1)) >= 'A') &&
(next <= 'Z')) {
ch = next;
i++;
} else if ((windowsName.length() > i + 1) &&
@ -1037,14 +1059,14 @@ class WindowsPreferences extends AbstractPreferences {
* to convert java string to a byte array of ASCII characters.
*/
private static byte[] toWindowsValueString(String javaName) {
StringBuffer windowsName = new StringBuffer();
StringBuilder windowsName = new StringBuilder();
for (int i = 0; i < javaName.length(); i++) {
char ch = javaName.charAt(i);
if ((ch < 0x0020) || (ch > 0x007f)){
// write \udddd
windowsName.append("/u");
String hex = Integer.toHexString(javaName.charAt(i));
StringBuffer hex4 = new StringBuffer(hex);
StringBuilder hex4 = new StringBuilder(hex);
hex4.reverse();
int len = 4 - hex4.length();
for (int j = 0; j < len; j++){
@ -1058,7 +1080,7 @@ class WindowsPreferences extends AbstractPreferences {
} else if (ch == '/') {
windowsName.append('\\');
} else if ((ch >= 'A') && (ch <='Z')) {
windowsName.append("/" + ch);
windowsName.append('/').append(ch);
} else {
windowsName.append(ch);
}
@ -1070,8 +1092,9 @@ class WindowsPreferences extends AbstractPreferences {
* Returns native handle for the top Windows node for this node.
*/
private int rootNativeHandle() {
return (isUserNode()? USER_ROOT_NATIVE_HANDLE :
SYSTEM_ROOT_NATIVE_HANDLE);
return (isUserNode()
? USER_ROOT_NATIVE_HANDLE
: SYSTEM_ROOT_NATIVE_HANDLE);
}
/**
@ -1090,7 +1113,7 @@ class WindowsPreferences extends AbstractPreferences {
* Converts a null-terminated byte array to java string
*/
private static String byteArrayToString(byte[] array) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (int i = 0; i < array.length - 1; i++) {
result.append((char)array[i]);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -67,7 +67,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
* value of this <code>SerialBlob</code> object.
* @serial
*/
private byte buf[];
private byte[] buf;
/**
* The internal representation of the <code>Blob</code> object on which this
@ -103,7 +103,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
* @throws SerialException if an error occurs during serialization
* @throws SQLException if a SQL errors occurs
*/
public SerialBlob(byte[] b) throws SerialException, SQLException {
public SerialBlob(byte[] b)
throws SerialException, SQLException {
len = b.length;
buf = new byte[(int)len];
@ -133,19 +134,17 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
* to this constructor is a <code>null</code>.
* @see java.sql.Blob
*/
public SerialBlob (Blob blob) throws SerialException, SQLException {
public SerialBlob (Blob blob)
throws SerialException, SQLException {
if (blob == null) {
throw new SQLException("Cannot instantiate a SerialBlob " +
"object with a null Blob object");
throw new SQLException(
"Cannot instantiate a SerialBlob object with a null Blob object");
}
len = blob.length();
buf = blob.getBytes(1, (int)len );
this.blob = blob;
//if ( len < 10240000)
// len = 10240000;
origLen = len;
}
@ -247,6 +246,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
*/
public long position(byte[] pattern, long start)
throws SerialException, SQLException {
isValid();
if (start < 1 || start > len) {
return -1;
@ -318,7 +318,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
*/
public int setBytes(long pos, byte[] bytes)
throws SerialException, SQLException {
return (setBytes(pos, bytes, 0, bytes.length));
return setBytes(pos, bytes, 0, bytes.length);
}
/**
@ -404,6 +404,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
*/
public java.io.OutputStream setBinaryStream(long pos)
throws SerialException, SQLException {
isValid();
if (this.blob != null) {
return this.blob.setBinaryStream(pos);
@ -426,11 +427,10 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
* if {@code free} had previously been called on this object
*/
public void truncate(long length) throws SerialException {
isValid();
if (length > len) {
throw new SerialException
("Length more than what can be truncated");
throw new SerialException(
"Length more than what can be truncated");
} else if((int)length == 0) {
buf = new byte[0];
len = length;
@ -467,8 +467,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
throw new SerialException("Invalid position in BLOB object set");
}
if (length < 1 || length > len - pos + 1) {
throw new SerialException("length is < 1 or pos + length >"
+ "total number of bytes");
throw new SerialException(
"length is < 1 or pos + length > total number of bytes");
}
return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
}
@ -544,7 +544,6 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
@ -591,8 +590,8 @@ public class SerialBlob implements Blob, Serializable, Cloneable {
*/
private void isValid() throws SerialException {
if (buf == null) {
throw new SerialException("Error: You cannot call a method on a "
+ "SerialBlob instance once free() has been called.");
throw new SerialException("Error: You cannot call a method on a " +
"SerialBlob instance once free() has been called.");
}
}