From e54f105bc0b25cc6f43ee1632ab7e0c3e4fdbd66 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 1 Sep 2015 18:56:44 +0000 Subject: [PATCH] Fix some Forbidden APIs errors git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700641 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/extractor/ExcelExtractor.java | 3 ++- .../org/apache/poi/hssf/record/HeaderFooterRecord.java | 5 +++-- .../org/apache/poi/hssf/record/RecordInputStream.java | 3 ++- src/java/org/apache/poi/hssf/record/UnknownRecord.java | 9 ++++++--- src/java/org/apache/poi/hssf/record/UserSViewBegin.java | 7 ++++--- src/java/org/apache/poi/hssf/record/UserSViewEnd.java | 4 +++- .../org/apache/poi/hssf/record/cf/FontFormatting.java | 4 +++- .../org/apache/poi/hssf/usermodel/HSSFDataFormat.java | 9 ++------- src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java | 5 +++-- src/java/org/apache/poi/ss/format/CellFormatPart.java | 3 ++- .../org/apache/poi/ss/format/CellGeneralFormatter.java | 3 ++- .../apache/poi/ss/formula/ptg/AbstractFunctionPtg.java | 5 +++-- src/java/org/apache/poi/ss/usermodel/ExtendedColor.java | 4 +++- src/java/org/apache/poi/ss/util/NumberComparer.java | 4 +++- src/java/org/apache/poi/ss/util/SheetUtil.java | 5 +++-- 15 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java index 57c6e01ca7..42571f1c2b 100644 --- a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java @@ -22,6 +22,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.util.Locale; import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.hssf.usermodel.HSSFCell; @@ -159,7 +160,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p if (i >= args.length) { throw new CommandParseException("Expected value after '" + args[i-1] + "'"); } - String value = args[i].toUpperCase(); + String value = args[i].toUpperCase(Locale.ROOT); if ("Y".equals(value) || "YES".equals(value) || "ON".equals(value) || "TRUE".equals(value)) { return true; } diff --git a/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java b/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java index 3eb602463f..c61725c5fd 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java +++ b/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java @@ -21,6 +21,7 @@ import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; import java.util.Arrays; +import java.util.Locale; /** * The HEADERFOOTER record stores information added in Office Excel 2007 for headers/footers. @@ -88,7 +89,7 @@ public final class HeaderFooterRecord extends StandardRecord { StringBuffer sb = new StringBuffer(); sb.append("[").append("HEADERFOOTER").append("] (0x"); - sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); + sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append("[/").append("HEADERFOOTER").append("]\n"); return sb.toString(); @@ -100,4 +101,4 @@ public final class HeaderFooterRecord extends StandardRecord { } -} \ No newline at end of file +} diff --git a/src/java/org/apache/poi/hssf/record/RecordInputStream.java b/src/java/org/apache/poi/hssf/record/RecordInputStream.java index 9de7d68895..126092bd48 100644 --- a/src/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf.record; import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.util.Locale; import org.apache.poi.hssf.dev.BiffViewer; import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream; @@ -51,7 +52,7 @@ public final class RecordInputStream implements LittleEndianInput { @SuppressWarnings("serial") public static final class LeftoverDataException extends RuntimeException { public LeftoverDataException(int sid, int remainingByteCount) { - super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase() + super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase(Locale.ROOT) + "(" + getRecordName(sid) + ") left " + remainingByteCount + " bytes remaining still to be read."); } diff --git a/src/java/org/apache/poi/hssf/record/UnknownRecord.java b/src/java/org/apache/poi/hssf/record/UnknownRecord.java index f87953aba3..aa1e0e4495 100644 --- a/src/java/org/apache/poi/hssf/record/UnknownRecord.java +++ b/src/java/org/apache/poi/hssf/record/UnknownRecord.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.record; +import java.util.Locale; + import org.apache.poi.hssf.record.aggregates.PageSettingsBlock; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; @@ -85,7 +87,8 @@ public final class UnknownRecord extends StandardRecord { // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord // those sids are in a different number space. // TODO - put unknown OBJ sub-records in a different class - System.out.println("Unknown record 0x" + Integer.toHexString(_sid).toUpperCase()); + System.out.println("Unknown record 0x" + + Integer.toHexString(_sid).toUpperCase(Locale.ROOT)); } } @@ -114,7 +117,7 @@ public final class UnknownRecord extends StandardRecord { StringBuffer sb = new StringBuffer(); sb.append("[").append(biffName).append("] (0x"); - sb.append(Integer.toHexString(_sid).toUpperCase() + ")\n"); + sb.append(Integer.toHexString(_sid).toUpperCase(Locale.ROOT) + ")\n"); if (_rawData.length > 0) { sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); } @@ -213,7 +216,7 @@ public final class UnknownRecord extends StandardRecord { case 0x1007: return "CHARTLINEFORMAT"; } if (isObservedButUnknown(sid)) { - return "UNKNOWN-" + Integer.toHexString(sid).toUpperCase(); + return "UNKNOWN-" + Integer.toHexString(sid).toUpperCase(Locale.ROOT); } return null; diff --git a/src/java/org/apache/poi/hssf/record/UserSViewBegin.java b/src/java/org/apache/poi/hssf/record/UserSViewBegin.java index 92aaf8a131..1c4895a53e 100644 --- a/src/java/org/apache/poi/hssf/record/UserSViewBegin.java +++ b/src/java/org/apache/poi/hssf/record/UserSViewBegin.java @@ -17,10 +17,11 @@ package org.apache.poi.hssf.record; +import java.util.Locale; + import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; - /** * The UserSViewBegin record specifies settings for a custom view associated with the sheet. * This record also marks the start of custom view records, which save custom view settings. @@ -76,7 +77,7 @@ public final class UserSViewBegin extends StandardRecord { StringBuffer sb = new StringBuffer(); sb.append("[").append("USERSVIEWBEGIN").append("] (0x"); - sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); + sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append("[/").append("USERSVIEWBEGIN").append("]\n"); return sb.toString(); @@ -87,4 +88,4 @@ public final class UserSViewBegin extends StandardRecord { return cloneViaReserialise(); } -} \ No newline at end of file +} diff --git a/src/java/org/apache/poi/hssf/record/UserSViewEnd.java b/src/java/org/apache/poi/hssf/record/UserSViewEnd.java index 650704bcf3..aa72eacd5a 100644 --- a/src/java/org/apache/poi/hssf/record/UserSViewEnd.java +++ b/src/java/org/apache/poi/hssf/record/UserSViewEnd.java @@ -17,6 +17,8 @@ package org.apache.poi.hssf.record; +import java.util.Locale; + import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndianOutput; @@ -61,7 +63,7 @@ public final class UserSViewEnd extends StandardRecord { StringBuffer sb = new StringBuffer(); sb.append("[").append("USERSVIEWEND").append("] (0x"); - sb.append(Integer.toHexString(sid).toUpperCase() + ")\n"); + sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append("[/").append("USERSVIEWEND").append("]\n"); return sb.toString(); diff --git a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java index 60e573e9bc..79bdabeda3 100644 --- a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java +++ b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java @@ -18,6 +18,8 @@ package org.apache.poi.hssf.record.cf; +import java.util.Locale; + import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; @@ -533,7 +535,7 @@ public final class FontFormatting { { buffer.append(" .underline type is not modified\n"); } - buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase()).append("\n"); + buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase(Locale.ROOT)).append("\n"); buffer.append(" [/Font Formatting]\n"); return buffer.toString(); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java index b1cb174a99..6eecc7b2c9 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java @@ -15,17 +15,12 @@ limitations under the License. ==================================================================== */ - -/* - * HSSFDataFormat.java - * - * Created on December 18, 2001, 12:42 PM - */ package org.apache.poi.hssf.usermodel; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Vector; import org.apache.poi.hssf.model.InternalWorkbook; @@ -95,7 +90,7 @@ public final class HSSFDataFormat implements DataFormat { public short getFormat(String pFormat) { // Normalise the format string String format; - if (pFormat.toUpperCase().equals("TEXT")) { + if (pFormat.toUpperCase(Locale.ROOT).equals("TEXT")) { format = "@"; } else { format = pFormat; diff --git a/src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java b/src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java index dfcecddca9..2b6cb9ebdf 100644 --- a/src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java +++ b/src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java @@ -25,6 +25,7 @@ import java.security.Provider; import java.security.Security; import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; +import java.util.Locale; import javax.crypto.Cipher; import javax.crypto.Mac; @@ -424,7 +425,7 @@ public class CryptoFunctions { */ public static String xorHashPassword(String password) { int hashedPassword = createXorVerifier2(password); - return String.format("%1$08X", hashedPassword); + return String.format(Locale.ROOT, "%1$08X", hashedPassword); } /** @@ -434,7 +435,7 @@ public class CryptoFunctions { public static String xorHashPasswordReversed(String password) { int hashedPassword = createXorVerifier2(password); - return String.format("%1$02X%2$02X%3$02X%4$02X" + return String.format(Locale.ROOT, "%1$02X%2$02X%3$02X%4$02X" , ( hashedPassword >>> 0 ) & 0xFF , ( hashedPassword >>> 8 ) & 0xFF , ( hashedPassword >>> 16 ) & 0xFF diff --git a/src/java/org/apache/poi/ss/format/CellFormatPart.java b/src/java/org/apache/poi/ss/format/CellFormatPart.java index b91307bfce..9a966e1529 100644 --- a/src/java/org/apache/poi/ss/format/CellFormatPart.java +++ b/src/java/org/apache/poi/ss/format/CellFormatPart.java @@ -20,6 +20,7 @@ import org.apache.poi.hssf.util.HSSFColor; import javax.swing.*; import java.awt.*; +import java.util.Locale; import java.util.Map; import java.util.TreeMap; import java.util.regex.Matcher; @@ -60,7 +61,7 @@ public class CellFormatPart { for (HSSFColor color : colors.values()) { Class type = color.getClass(); String name = type.getSimpleName(); - if (name.equals(name.toUpperCase())) { + if (name.equals(name.toUpperCase(Locale.ROOT))) { short[] rgb = color.getTriplet(); Color c = new Color(rgb[0], rgb[1], rgb[2]); NAMED_COLORS.put(name, c); diff --git a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java index 8c067576f3..cb5d4a1bb1 100644 --- a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.format; import java.util.Formatter; +import java.util.Locale; /** * A formatter for the default "General" cell format. @@ -77,7 +78,7 @@ public class CellGeneralFormatter extends CellFormatter { } } } else if (value instanceof Boolean) { - toAppendTo.append(value.toString().toUpperCase()); + toAppendTo.append(value.toString().toUpperCase(Locale.ROOT)); } else { toAppendTo.append(value.toString()); } diff --git a/src/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java index 9e413c5fe2..6efd260663 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java @@ -17,10 +17,11 @@ package org.apache.poi.ss.formula.ptg; +import java.util.Locale; + import org.apache.poi.ss.formula.function.FunctionMetadata; import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; - /** * This class provides the base functionality for Excel sheet functions * There are two kinds of function Ptgs - tFunc and tFuncVar @@ -119,7 +120,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg { * false if the name should be assumed to be an external function. */ public static final boolean isBuiltInFunctionName(String name) { - short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase()); + short ix = FunctionMetadataRegistry.lookupIndexByName(name.toUpperCase(Locale.ROOT)); return ix >= 0; } diff --git a/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java b/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java index eaab553ace..7f65a40ef8 100644 --- a/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java +++ b/src/java/org/apache/poi/ss/usermodel/ExtendedColor.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.ss.usermodel; +import java.util.Locale; + import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.Color; @@ -136,7 +138,7 @@ public abstract class ExtendedColor implements Color { } sb.append(cs); } - return sb.toString().toUpperCase(); + return sb.toString().toUpperCase(Locale.ROOT); } /** diff --git a/src/java/org/apache/poi/ss/util/NumberComparer.java b/src/java/org/apache/poi/ss/util/NumberComparer.java index 49a27d2aab..1d7a8dbe0b 100644 --- a/src/java/org/apache/poi/ss/util/NumberComparer.java +++ b/src/java/org/apache/poi/ss/util/NumberComparer.java @@ -17,6 +17,8 @@ package org.apache.poi.ss.util; +import java.util.Locale; + import static org.apache.poi.ss.util.IEEEDouble.*; /** @@ -168,6 +170,6 @@ public final class NumberComparer { * for formatting double values in error messages */ private static String toHex(double a) { - return "0x" + Long.toHexString(Double.doubleToLongBits(a)).toUpperCase(); + return "0x" + Long.toHexString(Double.doubleToLongBits(a)).toUpperCase(Locale.ROOT); } } diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java index d7edbcb305..bd7ab67ee2 100644 --- a/src/java/org/apache/poi/ss/util/SheetUtil.java +++ b/src/java/org/apache/poi/ss/util/SheetUtil.java @@ -22,6 +22,7 @@ import java.awt.font.TextAttribute; import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; import java.text.AttributedString; +import java.util.Locale; import java.util.Map; import org.apache.poi.ss.usermodel.Cell; @@ -148,7 +149,7 @@ public class SheetUtil { sval = String.valueOf(cell.getNumericCellValue()); } } else if (cellType == Cell.CELL_TYPE_BOOLEAN) { - sval = String.valueOf(cell.getBooleanCellValue()).toUpperCase(); + sval = String.valueOf(cell.getBooleanCellValue()).toUpperCase(Locale.ROOT); } if(sval != null) { String txt = sval + defaultChar; @@ -315,4 +316,4 @@ public class SheetUtil { // live within any merged regions return null; } -} \ No newline at end of file +} -- 2.39.5