diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-04-02 23:54:48 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-04-02 23:54:48 +0000 |
commit | 1dc771394bedaf456b85e9e15d90f7429908919b (patch) | |
tree | dfc772532f1a6f663c71fc1647acbd73e33fce9c /src/java/org/apache/poi | |
parent | 3f7d718a67d7f2830b186557d200ecba00d8ac34 (diff) | |
download | poi-1dc771394bedaf456b85e9e15d90f7429908919b.tar.gz poi-1dc771394bedaf456b85e9e15d90f7429908919b.zip |
Sonar Fixes - "static" base class members should not be accessed via derived types
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876067 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
6 files changed, 120 insertions, 78 deletions
diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 0e8dc08c6e..ed57f41967 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -57,7 +57,7 @@ public class VariantSupport extends Variant { Variant.VT_FILETIME, Variant.VT_LPSTR, Variant.VT_LPWSTR, Variant.VT_CF, Variant.VT_BOOL }; - + private static final POILogger logger = POILogFactory.getLogger(VariantSupport.class); //arbitrarily selected; may need to increase private static final int MAX_RECORD_LENGTH = 100_000; @@ -69,10 +69,10 @@ public class VariantSupport extends Variant { * been issued for. */ private static List<Long> unsupportedMessage; - + private static final byte[] paddingBytes = new byte[3]; - + /** * Specifies whether warnings about unsupported variant types are to be * written to {@code System.err} or not. @@ -166,7 +166,7 @@ public class VariantSupport extends Variant { LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(src, offset); return read( lei, length, type, codepage ); } - + public static Object read( LittleEndianByteArrayInputStream lei, final int length, final long type, final int codepage ) throws ReadingNotSupportedException, UnsupportedEncodingException { @@ -233,7 +233,7 @@ public class VariantSupport extends Variant { * * August 20, 2009 */ - // l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE; + // l1 = LittleEndian.getInt(src, o1); o1 += LittleEndianConts.INT_SIZE; // } // final byte[] v = new byte[l1]; // System.arraycopy(src, o1, v, 0, v.length); @@ -246,7 +246,7 @@ public class VariantSupport extends Variant { case Variant.VT_BOOL: VariantBool bool = (VariantBool) typedPropertyValue.getValue(); return bool.getValue(); - + /* * it is not very good, but what can do without breaking current * API? --sergey @@ -359,7 +359,7 @@ public class VariantSupport extends Variant { if (bi.bitLength() > 64) { throw new WritingNotSupportedException(type, value); } - + byte[] biBytesBE = bi.toByteArray(), biBytesLE = new byte[LittleEndianConsts.LONG_SIZE]; int i=biBytesBE.length; for (byte b : biBytesBE) { @@ -368,7 +368,7 @@ public class VariantSupport extends Variant { } i--; } - + out.write(biBytesLE); length = LittleEndianConsts.LONG_SIZE; } @@ -383,7 +383,7 @@ public class VariantSupport extends Variant { } break; } - + case Variant.VT_R8: if (value instanceof Number) { LittleEndian.putDouble( ((Number)value).doubleValue(), out); @@ -412,7 +412,7 @@ public class VariantSupport extends Variant { throw new WritingNotSupportedException(type, value); } } - + /* pad values to 4-bytes */ int padding = (4-(length & 0x3)) & 0x3; out.write(paddingBytes, 0, padding); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 1a877ee3ce..b3a74e69f8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -36,24 +36,62 @@ import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.Picture; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.ImageUtils; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.poi.util.Removal; import org.apache.poi.util.StringUtil; /** * Represents a escher picture. Eg. A GIF, JPEG etc... */ public class HSSFPicture extends HSSFSimpleShape implements Picture { - @SuppressWarnings("unused") - private static POILogger logger = POILogFactory.getLogger(HSSFPicture.class); - - public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile - public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile - public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT - public static final int PICTURE_TYPE_JPEG = HSSFWorkbook.PICTURE_TYPE_JPEG; // JFIF - public static final int PICTURE_TYPE_PNG = HSSFWorkbook.PICTURE_TYPE_PNG; // PNG - public static final int PICTURE_TYPE_DIB = HSSFWorkbook.PICTURE_TYPE_DIB; // Windows DIB + /** + * Windows Enhanced Metafile + * @deprecated use {@link Workbook#PICTURE_TYPE_EMF} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_EMF = Workbook.PICTURE_TYPE_EMF; + + /** + * Windows Metafile + * @deprecated use {@link Workbook#PICTURE_TYPE_WMF} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_WMF = Workbook.PICTURE_TYPE_WMF; + + /** + * Macintosh PICT + * @deprecated use {@link Workbook#PICTURE_TYPE_PICT} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_PICT = Workbook.PICTURE_TYPE_PICT; + + /** + * JFIF / JPEG + * @deprecated use {@link Workbook#PICTURE_TYPE_JPEG} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_JPEG = Workbook.PICTURE_TYPE_JPEG; + + /** + * PNG + * @deprecated use {@link Workbook#PICTURE_TYPE_PNG} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_PNG = Workbook.PICTURE_TYPE_PNG; + + /** + * Windows DIB + * @deprecated use {@link Workbook#PICTURE_TYPE_DIB} + */ + @Removal(version = "5.0.0") + @Deprecated + public static final int PICTURE_TYPE_DIB = Workbook.PICTURE_TYPE_DIB; public HSSFPicture(EscherContainerRecord spContainer, ObjRecord objRecord) { super(spContainer, objRecord); @@ -88,6 +126,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { protected EscherContainerRecord createSpContainer() { EscherContainerRecord spContainer = super.createSpContainer(); EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID); + assert(opt != null); opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__LINEDASHING); opt.removeEscherProperty(EscherPropertyTypes.LINESTYLE__NOLINEDRAWDASH); spContainer.removeChildRecord(spContainer.getChildById(EscherTextboxRecord.RECORD_ID)); @@ -96,7 +135,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { /** * Reset the image to the dimension of the embedded image - * + * * <p> * Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). @@ -117,7 +156,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { public void resize(double scale) { resize(scale,scale); } - + /** * Resize the image * <p> @@ -129,7 +168,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { * <code>resize(1.0,1.0)</code> keeps the original size,<br> * <code>resize(0.5,0.5)</code> resize to 50% of the original,<br> * <code>resize(2.0,2.0)</code> resizes to 200% of the original.<br> - * <code>resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE})</code> resizes to the dimension of the embedded image. + * <code>resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE})</code> resizes to the dimension of the embedded image. * </p> * * @param scaleX the amount by which the image width is multiplied relative to the original width. @@ -175,7 +214,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { public HSSFClientAnchor getPreferredSize(double scale){ return getPreferredSize(scale, scale); } - + /** * Calculate the preferred size for this picture. * @@ -203,7 +242,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { int type = bse.getBlipTypeWin32(); return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); } - + /** * Return picture data for this shape * @@ -215,7 +254,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { if (picIdx == -1) { return null; } - + HSSFPatriarch patriarch = getPatriarch(); HSSFShape parent = getParent(); while(patriarch == null && parent != null) { @@ -252,9 +291,9 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { ? "" : StringUtil.getFromUnicodeLE(propFile.getComplexData()).trim(); } - + public void setFileName(String data){ - // TODO: add trailing \u0000? + // TODO: add trailing \u0000? byte[] bytes = StringUtil.getToUnicodeLE(data); EscherComplexProperty prop = new EscherComplexProperty(EscherPropertyTypes.BLIP__BLIPFILENAME, true, bytes.length); prop.setComplexData(bytes); @@ -274,7 +313,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise(); return new HSSFPicture(spContainer, obj); } - + /** * @return the anchor that is used by this picture. */ @@ -284,7 +323,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { return (a instanceof HSSFClientAnchor) ? (HSSFClientAnchor)a : null; } - + /** * @return the sheet which contains the picture shape */ diff --git a/src/java/org/apache/poi/poifs/storage/BATBlock.java b/src/java/org/apache/poi/poifs/storage/BATBlock.java index 4e381f7b6c..4a2f3f3b8f 100644 --- a/src/java/org/apache/poi/poifs/storage/BATBlock.java +++ b/src/java/org/apache/poi/poifs/storage/BATBlock.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.poi.poifs.common.POIFSBigBlockSize; import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; /** * A block of block allocation table entries. BATBlocks are created @@ -39,30 +40,30 @@ public final class BATBlock implements BlockWritable { private POIFSBigBlockSize bigBlockSize; /** - * For a regular fat block, these are 128 / 1024 + * For a regular fat block, these are 128 / 1024 * next sector values. * For a XFat (DIFat) block, these are 127 / 1023 * next sector values, then a chaining value. */ private int[] _values; - + /** * Does this BATBlock have any free sectors in it? */ private boolean _has_free_sectors; - + /** * Where in the file are we? */ private int ourBlockIndex; - + /** * Create a single instance initialized with default values */ private BATBlock(POIFSBigBlockSize bigBlockSize) { this.bigBlockSize = bigBlockSize; - + int _entries_per_block = bigBlockSize.getBATEntriesPerBlock(); _values = new int[_entries_per_block]; _has_free_sectors = true; @@ -89,19 +90,19 @@ public final class BATBlock implements BlockWritable { { // Create an empty block BATBlock block = new BATBlock(bigBlockSize); - + // Fill it - byte[] buffer = new byte[LittleEndian.INT_SIZE]; + byte[] buffer = new byte[LittleEndianConsts.INT_SIZE]; for(int i=0; i<block._values.length; i++) { data.get(buffer); block._values[i] = LittleEndian.getInt(buffer); } block.recomputeFree(); - + // All done return block; } - + /** * Creates a single BATBlock, with all the values set to empty. */ @@ -119,7 +120,7 @@ public final class BATBlock implements BlockWritable { * number of FAT (BAT) sectors specified. (We don't care if those BAT * blocks come from the 109 in the header, or from header + XBATS, it * won't affect the calculation) - * + * * The actual file size will be between [size of fatCount-1 blocks] and * [size of fatCount blocks]. * For 512 byte block sizes, this means we may over-estimate by up to 65kb. @@ -129,12 +130,12 @@ public final class BATBlock implements BlockWritable { final int numBATs) { // Header isn't FAT addressed long size = 1; - + // The header has up to 109 BATs, and extra ones are referenced // from XBATs // However, all BATs can contain 128/1024 blocks size += (((long)numBATs) * bigBlockSize.getBATEntriesPerBlock()); - + // So far we've been in sector counts, turn into bytes return size * bigBlockSize.getBigBlockSize(); } @@ -148,26 +149,26 @@ public final class BATBlock implements BlockWritable { * and the relative index within it. * The List of BATBlocks must be in sequential order */ - public static BATBlockAndIndex getBATBlockAndIndex(final int offset, + public static BATBlockAndIndex getBATBlockAndIndex(final int offset, final HeaderBlock header, final List<BATBlock> bats) { POIFSBigBlockSize bigBlockSize = header.getBigBlockSize(); int entriesPerBlock = bigBlockSize.getBATEntriesPerBlock(); - + int whichBAT = offset / entriesPerBlock; int index = offset % entriesPerBlock; return new BATBlockAndIndex( index, bats.get(whichBAT) ); } - + /** * Returns the BATBlock that handles the specified offset, * and the relative index within it, for the mini stream. * The List of BATBlocks must be in sequential order */ - public static BATBlockAndIndex getSBATBlockAndIndex(final int offset, + public static BATBlockAndIndex getSBATBlockAndIndex(final int offset, final HeaderBlock header, final List<BATBlock> sbats) { return getBATBlockAndIndex(offset, header, sbats); } - + /** * Does this BATBlock have any free sectors in it, or * is it full? @@ -190,20 +191,20 @@ public final class BATBlock implements BlockWritable { } return usedSectors; } - + public int getValueAt(int relativeOffset) { if(relativeOffset >= _values.length) { throw new ArrayIndexOutOfBoundsException( - "Unable to fetch offset " + relativeOffset + " as the " + + "Unable to fetch offset " + relativeOffset + " as the " + "BAT only contains " + _values.length + " entries" - ); + ); } return _values[relativeOffset]; } public void setValueAt(int relativeOffset, int value) { int oldValue = _values[relativeOffset]; _values[relativeOffset] = value; - + // Do we need to re-compute the free? if(value == POIFSConstants.UNUSED_BLOCK) { _has_free_sectors = true; @@ -213,7 +214,7 @@ public final class BATBlock implements BlockWritable { recomputeFree(); } } - + /** * Record where in the file we live */ @@ -221,7 +222,7 @@ public final class BATBlock implements BlockWritable { this.ourBlockIndex = index; } /** - * Retrieve where in the file we live + * Retrieve where in the file we live */ public int getOurBlockIndex() { return ourBlockIndex; @@ -246,18 +247,18 @@ public final class BATBlock implements BlockWritable { // Save it out block.put( serialize() ); } - + private byte[] serialize() { // Create the empty array byte[] data = new byte[ bigBlockSize.getBigBlockSize() ]; - + // Fill in the values int offset = 0; for (int _value : _values) { LittleEndian.putInt(data, offset, _value); - offset += LittleEndian.INT_SIZE; + offset += LittleEndianConsts.INT_SIZE; } - + // Done return data; } diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java index c3274d97f6..d210bc5429 100644 --- a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java +++ b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.Units; @@ -77,7 +78,7 @@ public class ImageHeaderWMF { public ImageHeaderWMF(byte[] data, final int off) { int offset = off; - int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key + int key = LittleEndian.getInt(data, offset); offset += LittleEndianConsts.INT_SIZE; //header key if (key != APMHEADER_KEY) { LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing"); handle = 0; @@ -90,16 +91,16 @@ public class ImageHeaderWMF { return; } - handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; - left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + handle = LittleEndian.getUShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + left = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + top = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + right = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + bottom = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; - inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; - reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; + inch = LittleEndian.getUShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; + reserved = LittleEndian.getInt(data, offset); offset += LittleEndianConsts.INT_SIZE; - checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + checksum = LittleEndian.getShort(data, offset); offset += LittleEndianConsts.SHORT_SIZE; if (checksum != getChecksum()){ LOG.log(POILogger.WARN, "WMF checksum does not match the header data"); } @@ -124,14 +125,14 @@ public class ImageHeaderWMF { public void write(OutputStream out) throws IOException { byte[] header = new byte[22]; int pos = 0; - LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndian.INT_SIZE; //header key - LittleEndian.putUShort(header, pos, 0); pos += LittleEndian.SHORT_SIZE; //hmf - LittleEndian.putUShort(header, pos, left); pos += LittleEndian.SHORT_SIZE; //left - LittleEndian.putUShort(header, pos, top); pos += LittleEndian.SHORT_SIZE; //top - LittleEndian.putUShort(header, pos, right); pos += LittleEndian.SHORT_SIZE; //right - LittleEndian.putUShort(header, pos, bottom); pos += LittleEndian.SHORT_SIZE; //bottom - LittleEndian.putUShort(header, pos, inch); pos += LittleEndian.SHORT_SIZE; //inch - LittleEndian.putInt(header, pos, 0); pos += LittleEndian.INT_SIZE; //reserved + LittleEndian.putInt(header, pos, APMHEADER_KEY); pos += LittleEndianConsts.INT_SIZE; //header key + LittleEndian.putUShort(header, pos, 0); pos += LittleEndianConsts.SHORT_SIZE; //hmf + LittleEndian.putUShort(header, pos, left); pos += LittleEndianConsts.SHORT_SIZE; //left + LittleEndian.putUShort(header, pos, top); pos += LittleEndianConsts.SHORT_SIZE; //top + LittleEndian.putUShort(header, pos, right); pos += LittleEndianConsts.SHORT_SIZE; //right + LittleEndian.putUShort(header, pos, bottom); pos += LittleEndianConsts.SHORT_SIZE; //bottom + LittleEndian.putUShort(header, pos, inch); pos += LittleEndianConsts.SHORT_SIZE; //inch + LittleEndian.putInt(header, pos, 0); pos += LittleEndianConsts.INT_SIZE; //reserved checksum = getChecksum(); LittleEndian.putUShort(header, pos, checksum); diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java index 3480343218..901a65c2f9 100644 --- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.format; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.FieldPosition; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Formatter; @@ -558,7 +559,7 @@ public class CellNumberFormatter extends CellFormatter { private void writeScientific(double value, StringBuffer output, Set<CellNumberStringMod> mods) { StringBuffer result = new StringBuffer(); - FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD); + FieldPosition fractionPos = new FieldPosition(NumberFormat.FRACTION_FIELD); decimalFmt.format(value, result, fractionPos); writeInteger(result, output, integerSpecials, mods, showGroupingSeparator); writeFractional(result, output); diff --git a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java index d046b684b6..a87e11e410 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java @@ -19,7 +19,7 @@ package org.apache.poi.ss.formula.ptg; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianOutput; @@ -208,7 +208,7 @@ public final class AttrPtg extends ControlPtg { public int getSize() { if (_jumpTable != null) { - return SIZE + (_jumpTable.length + 1) * LittleEndian.SHORT_SIZE; + return SIZE + (_jumpTable.length + 1) * LittleEndianConsts.SHORT_SIZE; } return SIZE; } |