Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

results of static analysis #522

Open
wants to merge 1 commit into
base: VERSION_11_4_7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class ListsToContentControlsTest {

protected static Logger log = LoggerFactory.getLogger(ListsToContentControls.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(ListsToContentControls.class); // same logger

private static org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class RunFontSelectorArabicTest {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

static String[] expectedFont = { "Times New Roman", "Times New Roman" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class RunFontSelectorCalibriCheckBoxTest {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

final static String FONT_WORD_2016_USES = "Segoe UI Symbol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

public class RunFontSelectorChinese2Test {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

static String[] expectedFont = { "SimSun", "SimSun","SimSun","SimSun","SimSun","SimSun","Times New Roman","SimSun","Times New Roman" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class RunFontSelectorJapaneseTest {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

static String[] expectedFont = { "MS Gothic", "MS Mincho"};
static String[] win10Base = { "MS Gothic", "Century"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class RunFontSelectorRussian1Test {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

static String[] expectedFont = { "Verdana"};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class RunFontSelectorRussian2Test {

protected static Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger
protected static final Logger log = LoggerFactory.getLogger(RunFontSelector.class); // same logger

static String[] expectedFont = { "Times New Roman"};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class AddPartTests {

protected static Logger log = LoggerFactory.getLogger(AddPartTests.class);
protected static final Logger log = LoggerFactory.getLogger(AddPartTests.class);

/**
* @throws java.lang.Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class AlteredPartsTest {

protected static Logger log = LoggerFactory.getLogger(AlteredPartsTest.class);
protected static final Logger log = LoggerFactory.getLogger(AlteredPartsTest.class);

private static String resourceDir = System.getProperty("user.dir") + "/src/test/resources/AlteredParts/";
/* All of the docx in resourceDir have had their docprops parts stripped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class PatcherTest {

protected static Logger log = LoggerFactory.getLogger(PatcherTest.class);
protected static final Logger log = LoggerFactory.getLogger(PatcherTest.class);

private static String resourceDir = System.getProperty("user.dir") + "/src/test/resources/AlteredParts/";

Expand Down
4 changes: 2 additions & 2 deletions docx4j-core/src/main/java/org/docx4j/Docx4J.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ protected static void removeDefinedCustomXmlParts(WordprocessingMLPackage wmlPac
}
}
if (!partsToRemove.isEmpty()) {
for (int i=0; i<partsToRemove.size(); i++) {
relationshipsPart.removePart(partsToRemove.get(i));
for (PartName partName : partsToRemove) {
relationshipsPart.removePart(partName);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docx4j-core/src/main/java/org/docx4j/Docx4jProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class Docx4jProperties {

protected static Logger log = LoggerFactory.getLogger(Docx4jProperties.class);
protected static final Logger log = LoggerFactory.getLogger(Docx4jProperties.class);

private static Properties properties;

Expand Down
57 changes: 17 additions & 40 deletions docx4j-core/src/main/java/org/docx4j/TraversalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.docx4j.utils.CompoundTraversalUtilVisitorCallback;
import org.docx4j.utils.SingleTraversalUtilVisitorCallback;
import org.docx4j.utils.TraversalUtilVisitor;
import org.docx4j.vml.CTShape;
import org.docx4j.wml.Br;
import org.docx4j.wml.CTBookmark;
import org.docx4j.wml.CTMarkupRange;
Expand Down Expand Up @@ -353,13 +354,12 @@ public static List<Object> getChildrenImpl(Object o) {

} else if (o instanceof org.docx4j.wml.Document) {
// since 3.3.4, so traverse visits Body as well. This is more correct, and potentially useful.
List<Object> artificialList = new ArrayList<Object>();
List<Object> artificialList = new ArrayList<>();
artificialList.add( ((org.docx4j.wml.Document)o).getBody() );
return artificialList;

} else if (o instanceof Br
|| o instanceof CTBookmark
|| o instanceof CTMarkupRange) {
|| o instanceof CTMarkupRange) {
return null;
} else if (o instanceof R.Tab
|| o instanceof R.LastRenderedPageBreak) {
Expand Down Expand Up @@ -401,7 +401,7 @@ public static List<Object> getChildrenImpl(Object o) {
if (handledGraphicData==null) {
// log.info("handleGraphicData returned an empty list");
if (log.isDebugEnabled()) {
log.debug(XmlUtils.marshaltoString(graphic, true, true, Context.jc,
log.debug(XmlUtils.marshaltoString(graphic, true, true, Context.jc,
"http://schemas.openxmlformats.org/drawingml/2006/main", "graphic", org.docx4j.dml.Graphic.class));
}
} else {
Expand All @@ -411,7 +411,7 @@ public static List<Object> getChildrenImpl(Object o) {
}
if (!artificialList.isEmpty())
return artificialList;

} else if (o instanceof org.docx4j.dml.wordprocessingDrawing.Inline) {
org.docx4j.dml.wordprocessingDrawing.Inline inline = (org.docx4j.dml.wordprocessingDrawing.Inline) o;
List<Object> artificialList = new ArrayList<Object>();
Expand All @@ -427,7 +427,7 @@ public static List<Object> getChildrenImpl(Object o) {
if (handledGraphicData==null) {
// log.info("handleGraphicData returned an empty list");
if (log.isDebugEnabled()) {
log.debug(XmlUtils.marshaltoString(graphic, true, true, Context.jc,
log.debug(XmlUtils.marshaltoString(graphic, true, true, Context.jc,
"http://schemas.openxmlformats.org/drawingml/2006/main", "graphic", org.docx4j.dml.Graphic.class));
}
} else {
Expand Down Expand Up @@ -471,12 +471,8 @@ public static List<Object> getChildrenImpl(Object o) {

} else if (o instanceof org.docx4j.vml.CTShape) {
// return ((org.docx4j.vml.CTShape)o).getAny();
List<Object> artificialList = new ArrayList<Object>();
for (JAXBElement<?> j : ((org.docx4j.vml.CTShape)o).getPathOrFormulasOrHandles() ) {
// System.out.println(XmlUtils.unwrap(j).getClass().getName() );
artificialList.add(j);
}
return artificialList;
// System.out.println(XmlUtils.unwrap(j).getClass().getName() );
return new ArrayList<Object>(((CTShape) o).getPathOrFormulasOrHandles());
} else if (o instanceof CTDataModel) {
CTDataModel dataModel = (CTDataModel)o;
List<Object> artificialList = new ArrayList<Object>();
Expand All @@ -500,8 +496,7 @@ public static List<Object> getChildrenImpl(Object o) {
} else if (o instanceof CTObject) {

CTObject ctObject = (CTObject)o;
List<Object> artificialList = new ArrayList<Object>();
artificialList.addAll(ctObject.getAnyAndAny());
List<Object> artificialList = new ArrayList<Object>(ctObject.getAnyAndAny());
if (ctObject.getControl()!=null) {
artificialList.add(ctObject.getControl() ); // CTControl
}
Expand All @@ -513,14 +508,9 @@ public static List<Object> getChildrenImpl(Object o) {
} else if (o instanceof org.docx4j.dml.CTGvmlShape) {

org.docx4j.dml.CTGvmlShape sp = (org.docx4j.dml.CTGvmlShape)o;
if (sp!=null
&& sp.getTxSp()!=null
&& sp.getTxSp().getTxBody()!=null) {
if (sp.getTxSp() != null && sp.getTxSp().getTxBody() != null) {

List<Object> artificialList = new ArrayList<Object>();
artificialList.addAll(sp.getTxSp().getTxBody().getP());

return artificialList;
return new ArrayList<>(sp.getTxSp().getTxBody().getP());
}
return null;

Expand All @@ -541,15 +531,12 @@ public static List<Object> getChildrenImpl(Object o) {
} else if (o instanceof org.docx4j.mce.AlternateContent) {
// we also want to traverse the fallback
AlternateContent ac = (AlternateContent)o;
List<Object> artificialList = new ArrayList<Object>();
artificialList.addAll(ac.getChoice());
List<Object> artificialList = new ArrayList<Object>(ac.getChoice());
artificialList.add(ac.getFallback());
return artificialList;
} else if (o instanceof org.docx4j.com.microsoft.schemas.office.word.x2010.wordprocessingShape.CTWordprocessingShape) {
org.docx4j.com.microsoft.schemas.office.word.x2010.wordprocessingShape.CTWordprocessingShape sp = (org.docx4j.com.microsoft.schemas.office.word.x2010.wordprocessingShape.CTWordprocessingShape)o;
if (sp!=null
&& sp.getTxbx()!=null
&& sp.getTxbx().getTxbxContent()!=null) {
if (sp.getTxbx() != null && sp.getTxbx().getTxbxContent() != null) {

return sp.getTxbx().getTxbxContent().getContent();
}
Expand All @@ -562,10 +549,9 @@ public static List<Object> getChildrenImpl(Object o) {
log.debug(o.getClass().getName() + " .. looking for method which returns list " );
try {
Method[] methods = o.getClass().getDeclaredMethods();
for (int i = 0; i<methods.length; i++) {
Method m = methods[i];
if (m.getReturnType().getName().equals("java.util.List") ) {
return (List<Object>)m.invoke(o);
for (Method m : methods) {
if (m.getReturnType().getName().equals("java.util.List")) {
return (List<Object>) m.invoke(o);
}
}

Expand All @@ -575,7 +561,7 @@ public static List<Object> getChildrenImpl(Object o) {
log.debug(".. no list member");
return null;
}



public static void replaceChildren(Object o, List<Object> newChildren) {
Expand Down Expand Up @@ -640,19 +626,12 @@ public static void replaceChildren(Object o, List<Object> newChildren) {
((org.docx4j.wml.SdtElement) o).getSdtContent().getContent().clear();
((org.docx4j.wml.SdtElement) o).getSdtContent().getContent().addAll(newChildren);

} else if (o instanceof org.docx4j.wml.CTTxbxContent) {

((org.docx4j.wml.CTTxbxContent) o).getEGBlockLevelElts().clear();
((org.docx4j.wml.CTTxbxContent) o).getEGBlockLevelElts().addAll(newChildren);

} else {

log.info("Don't know how to replaceChildren in " + o.getClass().getName() );

if (o instanceof org.w3c.dom.Node) {
log.warn(" IGNORED " + ((org.w3c.dom.Node) o).getNodeName());
} else {
// log.warn(" IGNORED " + o.getClass().getName());
}

}
Expand Down Expand Up @@ -776,12 +755,10 @@ public static void visit(WordprocessingMLPackage wmlPackage,
.getJaxbElement().getContent();
} else if (Namespaces.ENDNOTES.equals(rs.getType())) {
//elementList = ((EndnotesPart) relPart.getPart(rs)).getContent();
elementList = new ArrayList();
elementList.addAll(
((EndnotesPart) relPart.getPart(rs)).getJaxbElement().getEndnote() );
} else if (Namespaces.FOOTNOTES.equals(rs.getType())) {
//elementList = ((FootnotesPart) relPart.getPart(rs)).getContent();
elementList = new ArrayList();
elementList.addAll(
((FootnotesPart) relPart.getPart(rs)).getJaxbElement().getFootnote() );
} else if (Namespaces.COMMENTS.equals(rs.getType())) {
Expand Down
4 changes: 2 additions & 2 deletions docx4j-core/src/main/java/org/docx4j/UnitsOfMeasurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private static String getHex(float f) {

if (i < 16) {
// Pad so we have 2 digits
return "0" + hexValue;
return '0' + hexValue;
}
return hexValue;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ else if (pctFg == 100) {
return resColor;
}

private String calcHexColor(int value) {
private static String calcHexColor(int value) {
String ret = Integer.toHexString(value).toUpperCase();
return (ret.length() < 6 ?
"000000".substring(0, 6 - ret.length()) + ret :
Expand Down
2 changes: 1 addition & 1 deletion docx4j-core/src/main/java/org/docx4j/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class Version {

protected static Logger log = LoggerFactory.getLogger(Version.class);
protected static final Logger log = LoggerFactory.getLogger(Version.class);

private static Properties properties;

Expand Down
Loading