From: Andreas Beeker Date: Sat, 15 Aug 2015 11:57:57 +0000 (+0000) Subject: FindBugs - DLS_DEAD_LOCAL_STORE X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=05c92b7a191821f1313c65746e6ccb759af47116;p=poi.git FindBugs - DLS_DEAD_LOCAL_STORE git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1696038 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ddf/EscherComplexProperty.java b/src/java/org/apache/poi/ddf/EscherComplexProperty.java index 8cdd46f5a0..2fddc9d6b6 100644 --- a/src/java/org/apache/poi/ddf/EscherComplexProperty.java +++ b/src/java/org/apache/poi/ddf/EscherComplexProperty.java @@ -135,7 +135,6 @@ public class EscherComplexProperty extends EscherProperty { } public String toXml(String tab){ - String dataStr = HexDump.toHex( _complexData, 32); StringBuilder builder = new StringBuilder(); builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId())) .append("\" name=\"").append(getName()).append("\" blipId=\"") diff --git a/src/java/org/apache/poi/ddf/EscherDump.java b/src/java/org/apache/poi/ddf/EscherDump.java index 17ac2db36c..5621806e65 100644 --- a/src/java/org/apache/poi/ddf/EscherDump.java +++ b/src/java/org/apache/poi/ddf/EscherDump.java @@ -73,14 +73,12 @@ public final class EscherDump { short options; // 4 bits for the version and 12 bits for the instance short recordId; int recordBytesRemaining; // including enclosing records - StringBuffer stringBuf = new StringBuffer(); short nDumpSize; String recordName; boolean atEOF = false; while (!atEOF && (remainingBytes > 0)) { - stringBuf = new StringBuffer(); options = LittleEndian.readShort( in ); recordId = LittleEndian.readShort( in ); recordBytesRemaining = LittleEndian.readInt( in ); @@ -194,6 +192,7 @@ public final class EscherDump { recordName = "UNKNOWN ID"; } + StringBuilder stringBuf = new StringBuilder(); stringBuf.append( " " ); stringBuf.append( HexDump.toHex( recordId ) ); stringBuf.append( " " ).append( recordName ).append( " [" ); @@ -203,6 +202,7 @@ public final class EscherDump { stringBuf.append( "] instance: " ); stringBuf.append( HexDump.toHex( ( (short) ( options >> 4 ) ) ) ); out.println( stringBuf.toString() ); + stringBuf.setLength(0); if ( recordId == (short) 0xF007 && 36 <= remainingBytes && 36 <= recordBytesRemaining ) @@ -213,7 +213,7 @@ public final class EscherDump { // short n16; // int n32; - stringBuf = new StringBuffer( " btWin32: " ); + stringBuf = stringBuf.append( " btWin32: " ); n8 = (byte) in.read(); stringBuf.append( HexDump.toHex( n8 ) ); stringBuf.append( getBlipType( n8 ) ); diff --git a/src/java/org/apache/poi/hssf/model/LineShape.java b/src/java/org/apache/poi/hssf/model/LineShape.java index f2c542a324..d9f6e6371d 100644 --- a/src/java/org/apache/poi/hssf/model/LineShape.java +++ b/src/java/org/apache/poi/hssf/model/LineShape.java @@ -55,7 +55,6 @@ public class LineShape EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); - EscherRecord anchor = new EscherClientAnchorRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER ); @@ -74,7 +73,7 @@ public class LineShape sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); if (userAnchor.isVerticallyFlipped()) sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); - anchor = createAnchor(userAnchor); + EscherRecord anchor = createAnchor(userAnchor); clientData.setRecordId( EscherClientDataRecord.RECORD_ID ); clientData.setOptions( (short) 0x0000 ); diff --git a/src/java/org/apache/poi/hssf/model/PolygonShape.java b/src/java/org/apache/poi/hssf/model/PolygonShape.java index 1543e2df80..2d7b724a34 100644 --- a/src/java/org/apache/poi/hssf/model/PolygonShape.java +++ b/src/java/org/apache/poi/hssf/model/PolygonShape.java @@ -130,8 +130,6 @@ public class PolygonShape */ private ObjRecord createObjRecord( HSSFShape hssfShape, int shapeId ) { - HSSFShape shape = hssfShape; - ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.setObjectType( OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING ); diff --git a/src/java/org/apache/poi/hssf/model/TextboxShape.java b/src/java/org/apache/poi/hssf/model/TextboxShape.java index 44da1ed3da..d4379fd3af 100644 --- a/src/java/org/apache/poi/hssf/model/TextboxShape.java +++ b/src/java/org/apache/poi/hssf/model/TextboxShape.java @@ -84,7 +84,6 @@ public class TextboxShape EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); - EscherRecord anchor = new EscherClientAnchorRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); escherTextbox = new EscherTextboxRecord(); @@ -113,7 +112,7 @@ public class TextboxShape // sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); // if (userAnchor.isVerticallyFlipped()) // sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); - anchor = createAnchor( userAnchor ); + EscherRecord anchor = createAnchor( userAnchor ); clientData.setRecordId( EscherClientDataRecord.RECORD_ID ); clientData.setOptions( (short) 0x0000 ); escherTextbox.setRecordId( EscherTextboxRecord.RECORD_ID ); diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index b82d7fbb02..618a86b062 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -507,7 +507,7 @@ public final class HyperlinkRecord extends StandardRecord { //From the spec: An optional unsigned integer that MUST be 3 if present // but some files has 4 - int usKeyValue = in.readUShort(); + /*int usKeyValue = */ in.readUShort(); _address = StringUtil.readUnicodeLE(in, charDataSize/2); } else { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java index 79545327ba..f27675f714 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java @@ -72,21 +72,12 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin private HSSFFontFormatting getFontFormatting(boolean create) { FontFormatting fontFormatting = cfRuleRecord.getFontFormatting(); - if ( fontFormatting != null) - { - cfRuleRecord.setFontFormatting(fontFormatting); - return new HSSFFontFormatting(cfRuleRecord, workbook); - } - else if( create ) - { + if (fontFormatting == null) { + if (!create) return null; fontFormatting = new FontFormatting(); cfRuleRecord.setFontFormatting(fontFormatting); - return new HSSFFontFormatting(cfRuleRecord, workbook); - } - else - { - return null; } + return new HSSFFontFormatting(cfRuleRecord, workbook); } /** @@ -106,22 +97,14 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin private HSSFBorderFormatting getBorderFormatting(boolean create) { BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting(); - if ( borderFormatting != null) - { - cfRuleRecord.setBorderFormatting(borderFormatting); - return new HSSFBorderFormatting(cfRuleRecord, workbook); - } - else if( create ) - { + if (borderFormatting == null) { + if (!create) return null; borderFormatting = new BorderFormatting(); cfRuleRecord.setBorderFormatting(borderFormatting); - return new HSSFBorderFormatting(cfRuleRecord, workbook); - } - else - { - return null; } + return new HSSFBorderFormatting(cfRuleRecord, workbook); } + /** * @return - border formatting object if defined, null otherwise */ @@ -137,24 +120,14 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin return getBorderFormatting(true); } - private HSSFPatternFormatting getPatternFormatting(boolean create) - { + private HSSFPatternFormatting getPatternFormatting(boolean create) { PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting(); - if ( patternFormatting != null) - { - cfRuleRecord.setPatternFormatting(patternFormatting); - return new HSSFPatternFormatting(cfRuleRecord, workbook); - } - else if( create ) - { + if (patternFormatting == null) { + if (!create) return null; patternFormatting = new PatternFormatting(); cfRuleRecord.setPatternFormatting(patternFormatting); - return new HSSFPatternFormatting(cfRuleRecord, workbook); - } - else - { - return null; } + return new HSSFPatternFormatting(cfRuleRecord, workbook); } /** @@ -176,21 +149,17 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin private HSSFDataBarFormatting getDataBarFormatting(boolean create) { CFRule12Record cfRule12Record = getCFRule12Record(create); + if (cfRule12Record == null) return null; + DataBarFormatting databarFormatting = cfRule12Record.getDataBarFormatting(); - if (databarFormatting != null) - { - return new HSSFDataBarFormatting(cfRule12Record, sheet); - } - else if( create ) - { - databarFormatting = cfRule12Record.createDataBarFormatting(); - return new HSSFDataBarFormatting(cfRule12Record, sheet); - } - else - { - return null; + if (databarFormatting == null) { + if (!create) return null; + cfRule12Record.createDataBarFormatting(); } + + return new HSSFDataBarFormatting(cfRule12Record, sheet); } + /** * @return databar / data-bar formatting object if defined, null otherwise */ @@ -207,21 +176,16 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin private HSSFIconMultiStateFormatting getMultiStateFormatting(boolean create) { CFRule12Record cfRule12Record = getCFRule12Record(create); + if (cfRule12Record == null) return null; + IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting(); - if (iconFormatting != null) - { - return new HSSFIconMultiStateFormatting(cfRule12Record, sheet); - } - else if( create ) - { - iconFormatting = cfRule12Record.createMultiStateFormatting(); - return new HSSFIconMultiStateFormatting(cfRule12Record, sheet); - } - else - { - return null; + if (iconFormatting == null) { + if (!create) return null; + cfRule12Record.createMultiStateFormatting(); } + return new HSSFIconMultiStateFormatting(cfRule12Record, sheet); } + /** * @return icon / multi-state formatting object if defined, null otherwise */ @@ -238,21 +202,17 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin private HSSFColorScaleFormatting getColorScaleFormatting(boolean create) { CFRule12Record cfRule12Record = getCFRule12Record(create); + if (cfRule12Record == null) return null; + ColorGradientFormatting colorFormatting = cfRule12Record.getColorGradientFormatting(); - if (colorFormatting != null) - { - return new HSSFColorScaleFormatting(cfRule12Record, sheet); - } - else if( create ) - { - colorFormatting = cfRule12Record.createColorGradientFormatting(); - return new HSSFColorScaleFormatting(cfRule12Record, sheet); - } - else - { - return null; + if (colorFormatting == null) { + if (!create) return null; + cfRule12Record.createColorGradientFormatting(); } + + return new HSSFColorScaleFormatting(cfRule12Record, sheet); } + /** * @return color scale / gradient formatting object if defined, null otherwise */ diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java index f8c8af479e..dc20afd1fa 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java @@ -148,7 +148,6 @@ public final class HSSFName implements Name { // Update our comment, if there is one if(_commentRec != null) { - String oldName = _commentRec.getNameText(); _commentRec.setNameText(nameName); _book.getWorkbook().updateNameCommentRecordCache(_commentRec); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 268a680d60..7d4ec2fb3e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -36,7 +36,6 @@ import org.apache.poi.hssf.record.DrawingRecord; import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.NameRecord; -import org.apache.poi.hssf.record.NoteRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.hssf.record.SCLRecord; @@ -1448,11 +1447,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { return; } - NoteRecord[] noteRecs; if (moveComments) { - noteRecs = _sheet.getNoteRecords(); - } else { - noteRecs = NoteRecord.EMPTY_ARRAY; + _sheet.getNoteRecords(); } shiftMerged(startRow, endRow, n, true); diff --git a/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java b/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java index f6477fb9b5..a35eb16d7c 100644 --- a/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java +++ b/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java @@ -95,8 +95,7 @@ public class DataSpaceMapUtils { } public DataSpaceMap(LittleEndianInput is) { - @SuppressWarnings("unused") - int length = is.readInt(); + /*int length = */ is.readInt(); int entryCount = is.readInt(); entries = new DataSpaceMapEntry[entryCount]; for (int i=0; i2.3.5.4 RC4 CryptoAPI Encrypted Summary Stream */ - @SuppressWarnings("unused") public InputStream getDataStream(DirectoryNode dir) throws IOException, GeneralSecurityException { NPOIFSFileSystem fsOut = new NPOIFSFileSystem(); @@ -209,7 +208,7 @@ public class CryptoAPIDecryptor extends Decryptor { SeekableByteArrayInputStream sbis = new SeekableByteArrayInputStream(bos.toByteArray()); LittleEndianInputStream leis = new LittleEndianInputStream(sbis); int streamDescriptorArrayOffset = (int) leis.readUInt(); - int streamDescriptorArraySize = (int) leis.readUInt(); + /* int streamDescriptorArraySize = (int) */ leis.readUInt(); sbis.skip(streamDescriptorArrayOffset - 8); sbis.setBlock(0); int encryptedStreamDescriptorCount = (int) leis.readUInt(); @@ -222,7 +221,7 @@ public class CryptoAPIDecryptor extends Decryptor { entry.block = leis.readUShort(); int nameSize = leis.readUByte(); entry.flags = leis.readUByte(); - boolean isStream = StreamDescriptorEntry.flagStream.isSet(entry.flags); + // boolean isStream = StreamDescriptorEntry.flagStream.isSet(entry.flags); entry.reserved2 = leis.readInt(); entry.streamName = StringUtil.readUnicodeLE(leis, nameSize); leis.readShort(); diff --git a/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIEncryptionInfoBuilder.java b/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIEncryptionInfoBuilder.java index 2a8a872642..36df528766 100644 --- a/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIEncryptionInfoBuilder.java +++ b/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIEncryptionInfoBuilder.java @@ -35,11 +35,10 @@ public class CryptoAPIEncryptionInfoBuilder implements EncryptionInfoBuilder { /** * initialize the builder from a stream */ - @SuppressWarnings("unused") public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { this.info = info; - int hSize = dis.readInt(); + /* int hSize = */ dis.readInt(); header = new CryptoAPIEncryptionHeader(dis); verifier = new CryptoAPIEncryptionVerifier(dis, header); decryptor = new CryptoAPIDecryptor(this); diff --git a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptionInfoBuilder.java b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptionInfoBuilder.java index 43dc569511..d55c8e0d6f 100644 --- a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptionInfoBuilder.java +++ b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptionInfoBuilder.java @@ -40,8 +40,7 @@ public class StandardEncryptionInfoBuilder implements EncryptionInfoBuilder { public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { this.info = info; - @SuppressWarnings("unused") - int hSize = dis.readInt(); + /* int hSize = */ dis.readInt(); header = new StandardEncryptionHeader(dis); verifier = new StandardEncryptionVerifier(dis, header); diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java index 1a40372be0..1bdd1e829f 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java @@ -101,10 +101,10 @@ public class DrawTextParagraph implements Drawable { indent -= leftMargin; } - Double rightMargin = paragraph.getRightMargin(); - if (rightMargin == null) { - rightMargin = 0d; - } +// Double rightMargin = paragraph.getRightMargin(); +// if (rightMargin == null) { +// rightMargin = 0d; +// } //The vertical line spacing Double spacing = paragraph.getLineSpacing(); diff --git a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java index c3a9361e4e..ad2553fbe7 100644 --- a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java +++ b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java @@ -63,7 +63,7 @@ public class PresetGeometries extends LinkedHashMap { XMLEventReader staxReader = staxFactory.createXMLEventReader(is); XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter); // ignore StartElement: - XMLEvent evDoc = staxFiltRd.nextEvent(); + /* XMLEvent evDoc = */ staxFiltRd.nextEvent(); // JAXB: JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); diff --git a/src/java/org/apache/poi/ss/formula/functions/Address.java b/src/java/org/apache/poi/ss/formula/functions/Address.java index 379135f148..e0680dff66 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Address.java +++ b/src/java/org/apache/poi/ss/formula/functions/Address.java @@ -69,14 +69,14 @@ public class Address implements Function { throw new EvaluationException(ErrorEval.VALUE_INVALID); } - boolean a1; - if(args.length > 3){ - ValueEval ve = OperandResolver.getSingleValue(args[3], srcRowIndex, srcColumnIndex); - // TODO R1C1 style is not yet supported - a1 = ve == MissingArgEval.instance ? true : OperandResolver.coerceValueToBoolean(ve, false); - } else { - a1 = true; - } +// boolean a1; +// if(args.length > 3){ +// ValueEval ve = OperandResolver.getSingleValue(args[3], srcRowIndex, srcColumnIndex); +// // TODO R1C1 style is not yet supported +// a1 = ve == MissingArgEval.instance ? true : OperandResolver.coerceValueToBoolean(ve, false); +// } else { +// a1 = true; +// } String sheetName; if(args.length == 5){ diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java index 2cdfe0f671..3ea2e27afb 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java @@ -68,7 +68,7 @@ public class Office2010SignatureFacet extends SignatureFacet { } UnsignedSignaturePropertiesType unsignedSigProps = unsignedProps.getUnsignedSignatureProperties(); if (unsignedSigProps == null) { - unsignedSigProps = unsignedProps.addNewUnsignedSignatureProperties(); + /* unsignedSigProps = */ unsignedProps.addNewUnsignedSignatureProperties(); } Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true); diff --git a/src/ooxml/java/org/apache/poi/util/MethodUtils.java b/src/ooxml/java/org/apache/poi/util/MethodUtils.java deleted file mode 100644 index c006c85462..0000000000 --- a/src/ooxml/java/org/apache/poi/util/MethodUtils.java +++ /dev/null @@ -1,1334 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.util; - - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - -/** - *

Utility reflection methods focussed on methods in general rather than properties in particular.

- * - *

Known Limitations

- *

Accessing Public Methods In A Default Access Superclass

- *

There is an issue when invoking public methods contained in a default access superclass. - * Reflection locates these methods fine and correctly assigns them as public. - * However, an IllegalAccessException is thrown if the method is invoked.

- * - *

MethodUtils contains a workaround for this situation. - * It will attempt to call setAccessible on this method. - * If this call succeeds, then the method can be invoked as normal. - * This call will only succeed when the application has sufficient security privilages. - * If this call fails then a warning will be logged and the method may fail.

- * - * @author Craig R. McClanahan - * @author Ralph Schaer - * @author Chris Audley - * @author Rey François - * @author Gregor Raýman - * @author Jan Sorensen - * @author Robert Burrell Donkin - */ - -public class MethodUtils { - - // --------------------------------------------------------- Private Methods - - /** - * Only log warning about accessibility work around once. - *

- * Note that this is broken when this class is deployed via a shared - * classloader in a container, as the warning message will be emitted - * only once, not once per webapp. However making the warning appear - * once per webapp means having a map keyed by context classloader - * which introduces nasty memory-leak problems. As this warning is - * really optional we can ignore this problem; only one of the webapps - * will get the warning in its logs but that should be good enough. - */ - private static boolean loggedAccessibleWarning = false; - - /** - * Indicates whether methods should be cached for improved performance. - *

- * Note that when this class is deployed via a shared classloader in - * a container, this will affect all webapps. However making this - * configurable per webapp would mean having a map keyed by context classloader - * which may introduce memory-leak problems. - */ - private static boolean CACHE_METHODS = true; - - /** An empty class array */ - private static final Class[] EMPTY_CLASS_PARAMETERS = new Class[0]; - /** An empty object array */ - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - // --------------------------------------------------------- Public Methods - - /** - *

Invoke a named method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than invokeExactMethod(). - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeMethod(Object object,String methodName,Object [] args)}. - *

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeMethod( - Object object, - String methodName, - Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - Object[] args = {arg}; - return invokeMethod(object, methodName, args); - - } - - - /** - *

Invoke a named method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. - *

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeMethod( - Object object, - String methodName, - Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - int arguments = args.length; - Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeMethod(object, methodName, args, parameterTypes); - - } - - - /** - *

Invoke a named method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than {@link - * #invokeExactMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - * - * @param object invoke method on this object - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @param parameterTypes match these parameters - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeMethod( - Object object, - String methodName, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - Method method = getMatchingAccessibleMethod( - object.getClass(), - methodName, - parameterTypes); - if (method == null) { - throw new NoSuchMethodException("No such accessible method: " + - methodName + "() on object: " + object.getClass().getName()); - } - return method.invoke(object, args); - } - - - /** - *

Invoke a method whose parameter type matches exactly the object - * type.

- * - *

This is a convenient wrapper for - * {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. - *

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactMethod( - Object object, - String methodName, - Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - Object[] args = {arg}; - return invokeExactMethod(object, methodName, args); - - } - - - /** - *

Invoke a method whose parameter types match exactly the object - * types.

- * - *

This uses reflection to invoke the method obtained from a call to - * getAccessibleMethod().

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactMethod( - Object object, - String methodName, - Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - int arguments = args.length; - Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeExactMethod(object, methodName, args, parameterTypes); - - } - - - /** - *

Invoke a method whose parameter types match exactly the parameter - * types given.

- * - *

This uses reflection to invoke the method obtained from a call to - * getAccessibleMethod().

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @param parameterTypes match these parameters - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactMethod( - Object object, - String methodName, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - - Method method = getAccessibleMethod( - object.getClass(), - methodName, - parameterTypes); - if (method == null) { - throw new NoSuchMethodException("No such accessible method: " + - methodName + "() on object: " + object.getClass().getName()); - } - return method.invoke(object, args); - - } - - /** - *

Invoke a static method whose parameter types match exactly the parameter - * types given.

- * - *

This uses reflection to invoke the method obtained from a call to - * {@link #getAccessibleMethod(Class, String, Class[])}.

- * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @param parameterTypes match these parameters - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactStaticMethod( - Class objectClass, - String methodName, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - - Method method = getAccessibleMethod( - objectClass, - methodName, - parameterTypes); - if (method == null) { - throw new NoSuchMethodException("No such accessible method: " + - methodName + "() on class: " + objectClass.getName()); - } - return method.invoke(null, args); - - } - - /** - *

Invoke a named static method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than {@link #invokeExactMethod(Object, String, Object[], Class[])}. - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeStaticMethod(Class objectClass,String methodName,Object [] args)}. - *

- * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeStaticMethod( - Class objectClass, - String methodName, - Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - Object[] args = {arg}; - return invokeStaticMethod (objectClass, methodName, args); - - } - - - /** - *

Invoke a named static method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeStaticMethod(Class objectClass,String methodName,Object [] args,Class[] parameterTypes)}. - *

- * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeStaticMethod( - Class objectClass, - String methodName, - Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - int arguments = args.length; - Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeStaticMethod (objectClass, methodName, args, parameterTypes); - - } - - - /** - *

Invoke a named static method whose parameter type matches the object type.

- * - *

The behaviour of this method is less deterministic - * than {@link - * #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args,Class[] parameterTypes)}. - * It loops through all methods with names that match - * and then executes the first it finds with compatable parameters.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @param parameterTypes match these parameters - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeStaticMethod( - Class objectClass, - String methodName, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - Method method = getMatchingAccessibleMethod( - objectClass, - methodName, - parameterTypes); - if (method == null) { - throw new NoSuchMethodException("No such accessible method: " + - methodName + "() on class: " + objectClass.getName()); - } - return method.invoke(null, args); - } - - - /** - *

Invoke a static method whose parameter type matches exactly the object - * type.

- * - *

This is a convenient wrapper for - * {@link #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args)}. - *

- * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactStaticMethod( - Class objectClass, - String methodName, - Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - - Object[] args = {arg}; - return invokeExactStaticMethod (objectClass, methodName, args); - - } - - - /** - *

Invoke a static method whose parameter types match exactly the object - * types.

- * - *

This uses reflection to invoke the method obtained from a call to - * {@link #getAccessibleMethod(Class, String, Class[])}.

- * - * @param objectClass invoke static method on this class - * @param methodName get method with this name - * @param args use these arguments - treat null as empty array - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactStaticMethod( - Class objectClass, - String methodName, - Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException { - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - int arguments = args.length; - Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeExactStaticMethod(objectClass, methodName, args, parameterTypes); - - } - - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) with given name and a single parameter. If no such method - * can be found, return null. - * Basically, a convenience wrapper that constructs a Class - * array for you.

- * - * @param clazz get method from this class - * @param methodName get method with this name - * @param parameterType taking this type of parameter - * @return The accessible method - */ - public static Method getAccessibleMethod( - Class clazz, - String methodName, - Class parameterType) { - - Class[] parameterTypes = {parameterType}; - return getAccessibleMethod(clazz, methodName, parameterTypes); - - } - - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) with given name and parameters. If no such method - * can be found, return null. - * This is just a convenient wrapper for - * {@link #getAccessibleMethod(Method method)}.

- * - * @param clazz get method from this class - * @param methodName get method with this name - * @param parameterTypes with these parameters types - * @return The accessible method - */ - public static Method getAccessibleMethod( - Class clazz, - String methodName, - Class[] parameterTypes) { - - try { - MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, true); - Method method = getAccessibleMethod - (clazz, clazz.getMethod(methodName, parameterTypes)); - return method; - } catch (NoSuchMethodException e) { - return (null); - } - - } - - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) that implements the specified Method. If no such method - * can be found, return null.

- * - * @param method The method that we wish to call - * @return The accessible method - */ - public static Method getAccessibleMethod(Method method) { - - // Make sure we have a method to check - if (method == null) { - return (null); - } - - return getAccessibleMethod(method.getDeclaringClass(), method); - - } - - - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) that implements the specified Method. If no such method - * can be found, return null.

- * - * @param clazz The class of the object - * @param method The method that we wish to call - * @return The accessible method - */ - public static Method getAccessibleMethod(Class clazz, Method method) { - - // Make sure we have a method to check - if (method == null) { - return (null); - } - - // If the requested method is not public we cannot call it - if (!Modifier.isPublic(method.getModifiers())) { - return (null); - } - - boolean sameClass = true; - if (clazz == null) { - clazz = method.getDeclaringClass(); - } else { - sameClass = clazz.equals(method.getDeclaringClass()); - if (!method.getDeclaringClass().isAssignableFrom(clazz)) { - throw new IllegalArgumentException(clazz.getName() + - " is not assignable from " + method.getDeclaringClass().getName()); - } - } - - // If the class is public, we are done - if (Modifier.isPublic(clazz.getModifiers())) { - if (!sameClass && !Modifier.isPublic(method.getDeclaringClass().getModifiers())) { - setMethodAccessible(method); // Default access superclass workaround - } - return (method); - } - - String methodName = method.getName(); - Class[] parameterTypes = method.getParameterTypes(); - - // Check the implemented interfaces and subinterfaces - method = - getAccessibleMethodFromInterfaceNest(clazz, - methodName, - parameterTypes); - - // Check the superclass chain - if (method == null) { - method = getAccessibleMethodFromSuperclass(clazz, - methodName, - parameterTypes); - } - - return (method); - - } - - - // -------------------------------------------------------- Private Methods - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) by scanning through the superclasses. If no such method - * can be found, return null.

- * - * @param clazz Class to be checked - * @param methodName Method name of the method we wish to call - * @param parameterTypes The parameter type signatures - */ - private static Method getAccessibleMethodFromSuperclass - (Class clazz, String methodName, Class[] parameterTypes) { - - Class parentClazz = clazz.getSuperclass(); - while (parentClazz != null) { - if (Modifier.isPublic(parentClazz.getModifiers())) { - try { - return parentClazz.getMethod(methodName, parameterTypes); - } catch (NoSuchMethodException e) { - return null; - } - } - parentClazz = parentClazz.getSuperclass(); - } - return null; - } - - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) that implements the specified method, by scanning through - * all implemented interfaces and subinterfaces. If no such method - * can be found, return null.

- * - *

There isn't any good reason why this method must be private. - * It is because there doesn't seem any reason why other classes should - * call this rather than the higher level methods.

- * - * @param clazz Parent class for the interfaces to be checked - * @param methodName Method name of the method we wish to call - * @param parameterTypes The parameter type signatures - */ - private static Method getAccessibleMethodFromInterfaceNest - (Class clazz, String methodName, Class[] parameterTypes) { - - Method method = null; - - // Search up the superclass chain - for (; clazz != null; clazz = clazz.getSuperclass()) { - - // Check the implemented interfaces of the parent class - Class[] interfaces = clazz.getInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - - // Is this interface public? - if (!Modifier.isPublic(interfaces[i].getModifiers())) { - continue; - } - - // Does the method exist on this interface? - try { - method = interfaces[i].getDeclaredMethod(methodName, - parameterTypes); - } catch (NoSuchMethodException e) { - /* Swallow, if no method is found after the loop then this - * method returns null. - */ - } - if (method != null) { - return method; - } - - // Recursively check our parent interfaces - method = - getAccessibleMethodFromInterfaceNest(interfaces[i], - methodName, - parameterTypes); - if (method != null) { - return method; - } - - } - - } - - // If we found a method return it - if (method != null) { - return (method); - } - - // We did not find anything - return (null); - - } - - /** - *

Find an accessible method that matches the given name and has compatible parameters. - * Compatible parameters mean that every method parameter is assignable from - * the given parameters. - * In other words, it finds a method with the given name - * that will take the parameters given.

- * - *

This method is slightly undeterminstic since it loops - * through methods names and return the first matching method.

- * - *

This method is used by - * {@link - * #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. - * - *

This method can match primitive parameter by passing in wrapper classes. - * For example, a Boolean will match a primitive boolean - * parameter. - * - * @param clazz find method in this class - * @param methodName find method with this name - * @param parameterTypes find method with compatible parameters - * @return The accessible method - */ - public static Method getMatchingAccessibleMethod( - Class clazz, - String methodName, - Class[] parameterTypes) { - // trace logging - Log log = LogFactory.getLog(MethodUtils.class); - if (log.isTraceEnabled()) { - log.trace("Matching name=" + methodName + " on " + clazz); - } - MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false); - - // see if we can find the method directly - // most of the time this works and it's much faster - try { - Method method = clazz.getMethod(methodName, parameterTypes); - if (log.isTraceEnabled()) { - log.trace("Found straight match: " + method); - log.trace("isPublic:" + Modifier.isPublic(method.getModifiers())); - } - - setMethodAccessible(method); // Default access superclass workaround - - return method; - - } catch (NoSuchMethodException e) { /* SWALLOW */ } - - // search through all methods - int paramSize = parameterTypes.length; - Method bestMatch = null; - Method[] methods = clazz.getMethods(); - float bestMatchCost = Float.MAX_VALUE; - float myCost = Float.MAX_VALUE; - for (int i = 0, size = methods.length; i < size ; i++) { - if (methods[i].getName().equals(methodName)) { - // log some trace information - if (log.isTraceEnabled()) { - log.trace("Found matching name:"); - log.trace(methods[i]); - } - - // compare parameters - Class[] methodsParams = methods[i].getParameterTypes(); - int methodParamSize = methodsParams.length; - if (methodParamSize == paramSize) { - boolean match = true; - for (int n = 0 ; n < methodParamSize; n++) { - if (log.isTraceEnabled()) { - log.trace("Param=" + parameterTypes[n].getName()); - log.trace("Method=" + methodsParams[n].getName()); - } - if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { - if (log.isTraceEnabled()) { - log.trace(methodsParams[n] + " is not assignable from " - + parameterTypes[n]); - } - match = false; - break; - } - } - - if (match) { - // get accessible version of method - Method method = getAccessibleMethod(clazz, methods[i]); - if (method != null) { - if (log.isTraceEnabled()) { - log.trace(method + " accessible version of " - + methods[i]); - } - setMethodAccessible(method); // Default access superclass workaround - myCost = getTotalTransformationCost(parameterTypes,method.getParameterTypes()); - if ( myCost < bestMatchCost ) { - bestMatch = method; - bestMatchCost = myCost; - } - } - - log.trace("Couldn't find accessible method."); - } - } - } - } - if ( bestMatch == null ){ - // didn't find a match - log.trace("No match found."); - } - - return bestMatch; - } - - public static Constructor getMatchingAccessibleConstructor( - Class clazz, - Class[] parameterTypes) { - // trace logging - Log log = LogFactory.getLog(MethodUtils.class); - MethodDescriptor md = new MethodDescriptor(clazz, "dummy", parameterTypes, false); - - // see if we can find the method directly - // most of the time this works and it's much faster - try { - Constructor constructor = clazz.getConstructor(parameterTypes); - if (log.isTraceEnabled()) { - log.trace("Found straight match: " + constructor); - log.trace("isPublic:" + Modifier.isPublic(constructor.getModifiers())); - } - - setMethodAccessible(constructor); // Default access superclass workaround - - return constructor; - - } catch (NoSuchMethodException e) { /* SWALLOW */ } - - // search through all methods - int paramSize = parameterTypes.length; - Constructor bestMatch = null; - Constructor[] constructors = clazz.getConstructors(); - float bestMatchCost = Float.MAX_VALUE; - float myCost = Float.MAX_VALUE; - for (int i = 0, size = constructors.length; i < size ; i++) { - // compare parameters - Class[] methodsParams = constructors[i].getParameterTypes(); - int methodParamSize = methodsParams.length; - if (methodParamSize == paramSize) { - boolean match = true; - for (int n = 0 ; n < methodParamSize; n++) { - if (log.isTraceEnabled()) { - log.trace("Param=" + parameterTypes[n].getName()); - log.trace("Method=" + methodsParams[n].getName()); - } - if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { - if (log.isTraceEnabled()) { - log.trace(methodsParams[n] + " is not assignable from " - + parameterTypes[n]); - } - match = false; - break; - } - } - - if (match) { - // get accessible version of method - Constructor cons = (Constructor)constructors[i]; - myCost = getTotalTransformationCost(parameterTypes,cons.getParameterTypes()); - if ( myCost < bestMatchCost ) { - bestMatch = cons; - bestMatchCost = myCost; - } - } - } - } - if ( bestMatch == null ){ - // didn't find a match - log.trace("No match found."); - } - - return bestMatch; - } - - /** - * Try to make the method accessible - * @param method The source arguments - */ - private static void setMethodAccessible(Object method) { - try { - // - // XXX Default access superclass workaround - // - // When a public class has a default access superclass - // with public methods, these methods are accessible. - // Calling them from compiled code works fine. - // - // Unfortunately, using reflection to invoke these methods - // seems to (wrongly) to prevent access even when the method - // modifer is public. - // - // The following workaround solves the problem but will only - // work from sufficiently privilages code. - // - // Better workarounds would be greatfully accepted. - // - if (method instanceof Method) { - ((Method)method).setAccessible(true); - } else if (method instanceof Constructor) { - ((Constructor)method).setAccessible(true); - } else { - throw new RuntimeException("invalid parameter"); - } - - } catch (SecurityException se) { - // log but continue just in case the method.invoke works anyway - Log log = LogFactory.getLog(MethodUtils.class); - if (!loggedAccessibleWarning) { - boolean vulnerableJVM = false; - try { - String specVersion = System.getProperty("java.specification.version"); - if (specVersion.charAt(0) == '1' && - (specVersion.charAt(2) == '0' || - specVersion.charAt(2) == '1' || - specVersion.charAt(2) == '2' || - specVersion.charAt(2) == '3')) { - - vulnerableJVM = true; - } - } catch (SecurityException e) { - // don't know - so display warning - vulnerableJVM = true; - } - if (vulnerableJVM) { - log.warn( - "Current Security Manager restricts use of workarounds for reflection bugs " - + " in pre-1.4 JVMs."); - } - loggedAccessibleWarning = true; - } - log.debug("Cannot setAccessible on method. Therefore cannot use jvm access bug workaround.", se); - } - } - - /** - * Returns the sum of the object transformation cost for each class in the source - * argument list. - * @param srcArgs The source arguments - * @param destArgs The destination arguments - * @return The total transformation cost - */ - private static float getTotalTransformationCost(Class[] srcArgs, Class[] destArgs) { - - float totalCost = 0.0f; - for (int i = 0; i < srcArgs.length; i++) { - Class srcClass, destClass; - srcClass = srcArgs[i]; - destClass = destArgs[i]; - totalCost += getObjectTransformationCost(srcClass, destClass); - } - - return totalCost; - } - - /** - * Gets the number of steps required needed to turn the source class into the - * destination class. This represents the number of steps in the object hierarchy - * graph. - * @param srcClass The source class - * @param destClass The destination class - * @return The cost of transforming an object - */ - private static float getObjectTransformationCost(Class srcClass, Class destClass) { - float cost = 0.0f; - while (destClass != null && !destClass.equals(srcClass)) { - if (destClass.isInterface() && isAssignmentCompatible(destClass,srcClass)) { - // slight penalty for interface match. - // we still want an exact match to override an interface match, but - // an interface match should override anything where we have to get a - // superclass. - cost += 0.25f; - break; - } - cost++; - destClass = destClass.getSuperclass(); - } - - /* - * If the destination class is null, we've travelled all the way up to - * an Object match. We'll penalize this by adding 1.5 to the cost. - */ - if (destClass == null) { - cost += 1.5f; - } - - return cost; - } - - - /** - *

Determine whether a type can be used as a parameter in a method invocation. - * This method handles primitive conversions correctly.

- * - *

In order words, it will match a Boolean to a boolean, - * a Long to a long, - * a Float to a float, - * a Integer to a int, - * and a Double to a double. - * Now logic widening matches are allowed. - * For example, a Long will not match a int. - * - * @param parameterType the type of parameter accepted by the method - * @param parameterization the type of parameter being tested - * - * @return true if the assignement is compatible. - */ - public static final boolean isAssignmentCompatible(Class parameterType, Class parameterization) { - // try plain assignment - if (parameterType.isAssignableFrom(parameterization)) { - return true; - } - - if (parameterType.isPrimitive()) { - // this method does *not* do widening - you must specify exactly - // is this the right behaviour? - Class parameterWrapperClazz = getPrimitiveWrapper(parameterType); - if (parameterWrapperClazz != null) { - return parameterWrapperClazz.equals(parameterization); - } - } - - return false; - } - - /** - * Gets the wrapper object class for the given primitive type class. - * For example, passing boolean.class returns Boolean.class - * @param primitiveType the primitive type class for which a match is to be found - * @return the wrapper type associated with the given primitive - * or null if no match is found - */ - public static Class getPrimitiveWrapper(Class primitiveType) { - // does anyone know a better strategy than comparing names? - if (boolean.class.equals(primitiveType)) { - return Boolean.class; - } else if (float.class.equals(primitiveType)) { - return Float.class; - } else if (long.class.equals(primitiveType)) { - return Long.class; - } else if (int.class.equals(primitiveType)) { - return Integer.class; - } else if (short.class.equals(primitiveType)) { - return Short.class; - } else if (byte.class.equals(primitiveType)) { - return Byte.class; - } else if (double.class.equals(primitiveType)) { - return Double.class; - } else if (char.class.equals(primitiveType)) { - return Character.class; - } else { - - return null; - } - } - - /** - * Gets the class for the primitive type corresponding to the primitive wrapper class given. - * For example, an instance of Boolean.class returns a boolean.class. - * @param wrapperType the - * @return the primitive type class corresponding to the given wrapper class, - * null if no match is found - */ - public static Class getPrimitiveType(Class wrapperType) { - // does anyone know a better strategy than comparing names? - if (Boolean.class.equals(wrapperType)) { - return boolean.class; - } else if (Float.class.equals(wrapperType)) { - return float.class; - } else if (Long.class.equals(wrapperType)) { - return long.class; - } else if (Integer.class.equals(wrapperType)) { - return int.class; - } else if (Short.class.equals(wrapperType)) { - return short.class; - } else if (Byte.class.equals(wrapperType)) { - return byte.class; - } else if (Double.class.equals(wrapperType)) { - return double.class; - } else if (Character.class.equals(wrapperType)) { - return char.class; - } else { - Log log = LogFactory.getLog(MethodUtils.class); - if (log.isDebugEnabled()) { - log.debug("Not a known primitive wrapper class: " + wrapperType); - } - return null; - } - } - - /** - * Find a non primitive representation for given primitive class. - * - * @param clazz the class to find a representation for, not null - * @return the original class if it not a primitive. Otherwise the wrapper class. Not null - */ - public static Class toNonPrimitiveClass(Class clazz) { - if (clazz.isPrimitive()) { - Class primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz); - // the above method returns - if (primitiveClazz != null) { - return primitiveClazz; - } else { - return clazz; - } - } else { - return clazz; - } - } - - - /** - * Represents the key to looking up a Method by reflection. - */ - private static class MethodDescriptor { - private Class cls; - private String methodName; - private Class[] paramTypes; - private boolean exact; - private int hashCode; - - /** - * The sole constructor. - * - * @param cls the class to reflect, must not be null - * @param methodName the method name to obtain - * @param paramTypes the array of classes representing the paramater types - * @param exact whether the match has to be exact. - */ - public MethodDescriptor(Class cls, String methodName, Class[] paramTypes, boolean exact) { - if (cls == null) { - throw new IllegalArgumentException("Class cannot be null"); - } - if (methodName == null) { - throw new IllegalArgumentException("Method Name cannot be null"); - } - if (paramTypes == null) { - paramTypes = EMPTY_CLASS_PARAMETERS; - } - - this.cls = cls; - this.methodName = methodName; - this.paramTypes = paramTypes; - this.exact= exact; - - this.hashCode = methodName.length(); - } - /** - * Checks for equality. - * @param obj object to be tested for equality - * @return true, if the object describes the same Method. - */ - public boolean equals(Object obj) { - if (!(obj instanceof MethodDescriptor)) { - return false; - } - MethodDescriptor md = (MethodDescriptor)obj; - - return ( - exact == md.exact && - methodName.equals(md.methodName) && - cls.equals(md.cls) && - java.util.Arrays.equals(paramTypes, md.paramTypes) - ); - } - /** - * Returns the string length of method name. I.e. if the - * hashcodes are different, the objects are different. If the - * hashcodes are the same, need to use the equals method to - * determine equality. - * @return the string length of method name. - */ - public int hashCode() { - return hashCode; - } - } -} diff --git a/src/ooxml/java/org/apache/poi/util/XmlSort.java b/src/ooxml/java/org/apache/poi/util/XmlSort.java index 7a831b75f6..1a88b09300 100644 --- a/src/ooxml/java/org/apache/poi/util/XmlSort.java +++ b/src/ooxml/java/org/apache/poi/util/XmlSort.java @@ -187,7 +187,7 @@ public final class XmlSort * The constructor accepts an argument indicating whether the comparison order is the same as * the lexicographic order of the strings or the reverse. */ - public static final class QNameComparator implements Comparator + public static final class QNameComparator implements Comparator { public static final int ASCENDING = 1; public static final int DESCENDING = 2; @@ -202,10 +202,7 @@ public final class XmlSort "comparison orders"); } - public int compare(Object o, Object o1) - { - XmlCursor cursor1 = (XmlCursor) o; - XmlCursor cursor2 = (XmlCursor) o1; + public int compare(XmlCursor cursor1, XmlCursor cursor2) { QName qname1 = cursor1.getName(); QName qname2 = cursor2.getName(); int qnameComparisonRes = qname1.getNamespaceURI().compareTo(qname2.getNamespaceURI()); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java index b894cd080d..e5362c4d23 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java @@ -21,7 +21,6 @@ package org.apache.poi.xslf.usermodel; import org.apache.poi.sl.usermodel.ConnectorShape; import org.apache.poi.util.Beta; -import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; @@ -44,7 +43,6 @@ public class XSLFConnectorShape extends XSLFSimpleShape implements ConnectorShap /** * @param shapeId 1-based shapeId */ - @SuppressWarnings("unused") static CTConnector prototype(int shapeId) { CTConnector ct = CTConnector.Factory.newInstance(); CTConnectorNonVisual nvSpPr = ct.addNewNvCxnSpPr(); @@ -57,7 +55,7 @@ public class XSLFConnectorShape extends XSLFSimpleShape implements ConnectorShap CTPresetGeometry2D prst = spPr.addNewPrstGeom(); prst.setPrst(STShapeType.LINE); prst.addNewAvLst(); - CTLineProperties ln = spPr.addNewLn(); + /* CTLineProperties ln = */ spPr.addNewLn(); return ct; } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java index 2632738918..f26f3eb50b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java @@ -23,7 +23,12 @@ import javax.xml.namespace.QName; import org.apache.poi.util.Internal; import org.apache.xmlbeans.XmlCursor; -import org.openxmlformats.schemas.drawingml.x2006.main.*; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData; +import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrameNonVisual; import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; @@ -79,7 +84,7 @@ public final class XSSFGraphicFrame extends XSSFShape { offPoint.setX(0); offPoint.setY(0); - CTGraphicalObject graphic = graphicFrame.addNewGraphic(); + /* CTGraphicalObject graphic = */ graphicFrame.addNewGraphic(); prototype = graphicFrame; } diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java index 09d6d6b047..1efe14447a 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java @@ -94,7 +94,6 @@ public final class NewOleFile extends RandomAccessFile int counter = 0; for(int x = 0; x < _num_bbd_blocks; x++) { - byte[] bigBlock = new byte[512]; int offset = (_bbd_list[x] + 1) * 512; seek(offset); for(int y = 0; y < 128; y++) @@ -107,17 +106,12 @@ public final class NewOleFile extends RandomAccessFile initializePropertySets(rootChain); } - @SuppressWarnings("unused") - public static void main(String args[]) - { - try - { - NewOleFile file = new NewOleFile(args[0], "r"); - } - catch(Exception e) - { - } + + public static void main(String args[]) throws Exception { + NewOleFile nof = new NewOleFile(args[0], "r"); + nof.close(); } + protected int[] readChain(int[] blockChain, int startBlock) { int[] tempChain = new int[blockChain.length]; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java index ff53300321..2c0c11c61c 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java @@ -784,7 +784,6 @@ public final class WordDocument { return context.getFontMetrics(font); }*/ - @SuppressWarnings("unused") private String createRegion(boolean before, HeaderFooter header, SEP sep, String name) { if(header.isEmpty()) @@ -820,8 +819,8 @@ public final class WordDocument { sep._dyaBottom = Math.max(extent*20, sep._dyaBottom); } - int marginLeft = sep._dxaLeft/20; - int marginRight = sep._dxaRight/20; + //int marginLeft = sep._dxaLeft/20; + //int marginRight = sep._dxaRight/20; return ""; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java index 3a09d76146..1f7765c234 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java @@ -33,11 +33,11 @@ public final class HDFDocument public HDFDocument(InputStream in, HDFParsingListener listener) throws IOException { EventBridge eb = new EventBridge(listener); - HDFObjectFactory factory = new HDFObjectFactory(in, eb); + /* HDFObjectFactory factory = */ new HDFObjectFactory(in, eb); } public HDFDocument(InputStream in) throws IOException { _model = new HDFObjectModel(); - HDFObjectFactory factory = new HDFObjectFactory(in, _model); + /* HDFObjectFactory factory = */ new HDFObjectFactory(in, _model); } } diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java index ce9dcb3976..4ff9f60d57 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java @@ -68,19 +68,10 @@ public final class HDFObjectFactory { byte[] _tableBuffer; - @SuppressWarnings("unused") - public static void main(String args[]) - { - try - { - HDFObjectFactory f = new HDFObjectFactory(new FileInputStream("c:\\test.doc")); - int k = 0; - } - catch(Exception t) - { - t.printStackTrace(); - } + public static void main(String args[]) throws Exception { + new HDFObjectFactory(new FileInputStream("c:\\test.doc")); } + /** Creates a new instance of HDFObjectFactory * * @param istream The InputStream that is the Word document @@ -133,19 +124,23 @@ public final class HDFObjectFactory { List results = new ArrayList(1); //do Ole stuff - POIFSFileSystem filesystem = new POIFSFileSystem(istream); - - DocumentEntry headerProps = - (DocumentEntry)filesystem.getRoot().getEntry("WordDocument"); - - byte[] mainDocument = new byte[headerProps.getSize()]; - filesystem.createDocumentInputStream("WordDocument").read(mainDocument); - - FileInformationBlock fib = new FileInformationBlock(mainDocument); - - - results.add(fib); - return results; + POIFSFileSystem filesystem = null; + try { + filesystem = new POIFSFileSystem(istream); + DocumentEntry headerProps = + (DocumentEntry)filesystem.getRoot().getEntry("WordDocument"); + + byte[] mainDocument = new byte[headerProps.getSize()]; + filesystem.createDocumentInputStream("WordDocument").read(mainDocument); + + FileInformationBlock fib = new FileInformationBlock(mainDocument); + + + results.add(fib); + return results; + } finally { + if (filesystem != null) filesystem.close(); + } } @@ -477,7 +472,7 @@ public final class HDFObjectFactory { { int ccpText = _fib.getCcpText(); - int ccpFtn = _fib.getCcpFtn(); + // int ccpFtn = _fib.getCcpFtn(); //sections int fcMin = _fib.getFcMin(); diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java index 9ddb2da82f..c4a935d252 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java @@ -329,15 +329,14 @@ public final class StyleSheet implements HDFType { newCHP.setIco((byte)0); break; case 0x33: - try - { - newCHP = (CharacterProperties)oldCHP.clone(); - } - catch(CloneNotSupportedException e) - { - //do nothing - } - return; + // ... this code has no effect ... + // try { + // newCHP = (CharacterProperties)oldCHP.clone(); + // } + // catch(CloneNotSupportedException e) { + // //do nothing + // } + break; case 0x34: break; case 0x35: diff --git a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java index 2d8ad8e839..ad38755a0f 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java +++ b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java @@ -73,8 +73,7 @@ public final class CompressedRTF extends LZWDecompresser { compressedSize = LittleEndian.readInt(src); decompressedSize = LittleEndian.readInt(src); int compressionType = LittleEndian.readInt(src); - @SuppressWarnings("unused") - int dataCRC = LittleEndian.readInt(src); + /* int dataCRC = */ LittleEndian.readInt(src); // TODO - Handle CRC checking on the output side diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index c1deea8441..4af64ecb4c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -301,11 +301,8 @@ public final class HSLFSlideShow implements SlideShow { // Slides or Notes, and possibly even other odd stuff.... // About the only thing you can say is that the master details are in // the first SLWT. - SlideAtomsSet[] masterSets = new SlideAtomsSet[0]; if (masterSLWT != null) { - masterSets = masterSLWT.getSlideAtomsSets(); - - for (SlideAtomsSet sas : masterSets) { + for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) { Record r = getCoreRecordForSAS(sas); int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier(); if (r instanceof org.apache.poi.hslf.record.Slide) { @@ -327,27 +324,27 @@ public final class HSLFSlideShow implements SlideShow { // Start by finding the notes records to go with the entries in // notesSLWT org.apache.poi.hslf.record.Notes[] notesRecords; - SlideAtomsSet[] notesSets = new SlideAtomsSet[0]; Map slideIdToNotes = new HashMap(); if (notesSLWT == null) { // None notesRecords = new org.apache.poi.hslf.record.Notes[0]; } else { // Match up the records and the SlideAtomSets - notesSets = notesSLWT.getSlideAtomsSets(); List notesRecordsL = new ArrayList(); - for (int i = 0; i < notesSets.length; i++) { + int idx = -1; + for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) { + idx++; // Get the right core record - Record r = getCoreRecordForSAS(notesSets[i]); + Record r = getCoreRecordForSAS(notesSet); + SlidePersistAtom spa = notesSet.getSlidePersistAtom(); + String loggerLoc = "A Notes SlideAtomSet at "+idx+" said its record was at refID "+spa.getRefID(); + // Ensure it really is a notes record if (r == null || r instanceof org.apache.poi.hslf.record.Notes) { if (r == null) { - logger.log(POILogger.WARN, "A Notes SlideAtomSet at " + i - + " said its record was at refID " - + notesSets[i].getSlidePersistAtom().getRefID() - + ", but that record didn't exist - record ignored."); + logger.log(POILogger.WARN, loggerLoc+", but that record didn't exist - record ignored."); } // we need to add also null-records, otherwise the index references to other existing // don't work anymore @@ -355,14 +352,10 @@ public final class HSLFSlideShow implements SlideShow { notesRecordsL.add(notesRecord); // Record the match between slide id and these notes - SlidePersistAtom spa = notesSets[i].getSlidePersistAtom(); int slideId = spa.getSlideIdentifier(); - slideIdToNotes.put(slideId, i); + slideIdToNotes.put(slideId, idx); } else { - logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i - + " said its record was at refID " - + notesSets[i].getSlidePersistAtom().getRefID() - + ", but that was actually a " + r); + logger.log(POILogger.ERROR, loggerLoc+", but that was actually a " + r); } } notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()]; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java index 30397bfab8..99aa8c645f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java @@ -221,7 +221,7 @@ public class HSLFSlideShowEncrypted { cipher.doFinal(pictstream, offset, 8, pictstream, offset); recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset)); recType = LittleEndian.getUShort(pictstream, offset+2); - rlen = (int)LittleEndian.getUInt(pictstream, offset+4); + // rlen = (int)LittleEndian.getUInt(pictstream, offset+4); offset += 8; } @@ -299,7 +299,7 @@ public class HSLFSlideShowEncrypted { // update header data recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset)); recType = LittleEndian.getUShort(pictstream, offset+2); - rlen = (int)LittleEndian.getUInt(pictstream, offset+4); + // rlen = (int) LittleEndian.getUInt(pictstream, offset+4); cipher.doFinal(pictstream, offset, 8, pictstream, offset); offset += 8; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 529d733163..961c234102 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -752,10 +752,10 @@ public final class HSLFTextParagraph implements TextParagraph { RecordContainer _txtbox = headerAtom.getParentRecord(); Record[] cr = _txtbox.getChildRecords(); - int headerIdx = -1, textIdx = -1, styleIdx = -1; + int /* headerIdx = -1, */ textIdx = -1, styleIdx = -1; for (int i = 0; i < cr.length; i++) { Record r = cr[i]; - if (r == headerAtom) headerIdx = i; + if (r == headerAtom) ; // headerIdx = i; else if (r == oldRecord || r == newRecord) textIdx = i; else if (r == styleAtom) styleIdx = i; } @@ -763,7 +763,7 @@ public final class HSLFTextParagraph implements TextParagraph { if (textIdx == -1) { // the old record was never registered, ignore it _txtbox.addChildAfter(newRecord, headerAtom); - textIdx = headerIdx + 1; + // textIdx = headerIdx + 1; } else { // swap not appropriated records - noop if unchanged cr[textIdx] = newRecord; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java index 8669878ff8..076c15f2b0 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java @@ -112,7 +112,7 @@ public abstract class PropertiesChunk extends Chunk { return null; } if (val instanceof ChunkBasedPropertyValue) { - ChunkBasedPropertyValue cval = (ChunkBasedPropertyValue)val; + // ChunkBasedPropertyValue cval = (ChunkBasedPropertyValue)val; // TODO Lookup return Collections.emptyList(); } else { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 8aef34b214..19f7b84185 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -347,7 +347,7 @@ public final class HWPFDocument extends HWPFDocumentCore _ft = new FontTable(_tableStream, _fib.getFcSttbfffn(), _fib.getLcbSttbfffn()); int listOffset = _fib.getFcPlfLst(); - int lfoOffset = _fib.getFcPlfLfo(); + // int lfoOffset = _fib.getFcPlfLfo(); if ( listOffset != 0 && _fib.getLcbPlfLst() != 0 ) { _lt = new ListTables( _tableStream, listOffset, _fib.getFcPlfLfo(), diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index a070c4a991..25b8a8700e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -40,8 +40,8 @@ public final class StyleDescription implements HDFType private final static int PARAGRAPH_STYLE = 1; private final static int CHARACTER_STYLE = 2; - private final static int TABLE_STYLE = 3; - private final static int NUMBERING_STYLE = 4; + // private final static int TABLE_STYLE = 3; + // private final static int NUMBERING_STYLE = 4; private int _baseLength; private StdfBase _stdfBase; @@ -86,7 +86,7 @@ public final class StyleDescription implements HDFType if ( readStdfPost2000 ) { _stdfPost2000 = new StdfPost2000( std, offset ); - offset += StdfPost2000.getSize(); + // offset += StdfPost2000.getSize(); } //first byte(s) of variable length section of std is the length of the diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index ba213b7a4e..f8ec76b674 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -42,10 +42,10 @@ import org.apache.poi.util.LittleEndian; public final class StyleSheet implements HDFType { public static final int NIL_STYLE = 4095; - private static final int PAP_TYPE = 1; - private static final int CHP_TYPE = 2; - private static final int SEP_TYPE = 4; - private static final int TAP_TYPE = 5; +// private static final int PAP_TYPE = 1; +// private static final int CHP_TYPE = 2; +// private static final int SEP_TYPE = 4; +// private static final int TAP_TYPE = 5; @Deprecated private final static ParagraphProperties NIL_PAP = new ParagraphProperties(); @@ -144,7 +144,7 @@ public final class StyleSheet implements HDFType { _stshif.setCstd( _styleDescriptions.length ); _stshif.serialize( buf, offset ); - offset += Stshif.getSize(); + // offset += Stshif.getSize(); out.write(buf); @@ -156,7 +156,7 @@ public final class StyleSheet implements HDFType { byte[] std = _styleDescriptions[x].toByteArray(); // adjust the size so it is always on a word boundary - LittleEndian.putShort(sizeHolder, (short)((std.length) + (std.length % 2))); + LittleEndian.putShort(sizeHolder, 0, (short)((std.length) + (std.length % 2))); out.write(sizeHolder); out.write(std);