Skip to content

Commit

Permalink
Avoid invoking PropertyResolver constructor recursively.
Browse files Browse the repository at this point in the history
  • Loading branch information
plutext committed Jan 24, 2025
1 parent 190f802 commit 230f34f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,31 @@ public List<Object> getContent() {
return this.getJaxbElement().getContent();
}

private PropertyResolver propertyResolver;
private PropertyResolver propertyResolver;

/**
* get the PropertyResolver, creating if necessary
*/
public PropertyResolver getPropertyResolver() {
if (propertyResolver==null) {
return getPropertyResolver(true);
}

/**
* get the PropertyResolver
*
* @param create whether to create if null
* @return
* @since 11.5.2
*/
public PropertyResolver getPropertyResolver(boolean create) {
// create=false is only really necessary where a StackOverflow is a possibility;
// eg getPropertyResolver() being invoked from PropertyResolver's constructor.
if (create && propertyResolver == null) {
try {
propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack);
propertyResolver = new PropertyResolver((WordprocessingMLPackage) this.pack);
} catch (Docx4JException e) {
e.printStackTrace();
}
}
}
return propertyResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,40 @@ private Ind getIndFromLvl(Lvl lvl) {
// use any w:ind in it (or TODO styles it is based on)
if (lvl.getPStyle()!=null) {

log.debug("override level has linked style: " + lvl.getPStyle().getVal() );

// Get the style
// StyleDefinitionsPart stylesPart = ((WordprocessingMLPackage)this.getPackage()).
// getMainDocumentPart().getStyleDefinitionsPart();
org.docx4j.wml.Style style = null;
PropertyResolver propertyResolver
= ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getPropertyResolver();

log.debug("override level has linked style: " + lvl.getPStyle().getVal() );

org.docx4j.wml.Style style = propertyResolver.getStyle( lvl.getPStyle().getVal() );
= ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getPropertyResolver(false);
/* avoids invoking it during init:
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:163)
at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getIndFromLvl(NumberingDefinitionsPart.java:417)
at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getInd(NumberingDefinitionsPart.java:401)
at org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart.getInd(NumberingDefinitionsPart.java:365)
at org.docx4j.model.styles.StyleUtil.apply(StyleUtil.java:1941)
at org.docx4j.model.styles.StyleUtil.apply(StyleUtil.java:1896)
at org.docx4j.model.PropertyResolver.applyPPr(PropertyResolver.java:842)
at org.docx4j.model.PropertyResolver.addNormalToResolvedStylePPrComponent(PropertyResolver.java:234)
at org.docx4j.model.PropertyResolver.init(PropertyResolver.java:212)
at org.docx4j.model.PropertyResolver.<init>(PropertyResolver.java:145)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:163)
*/
if (propertyResolver==null) {
// less efficient
StyleDefinitionsPart stylesPart = ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getStyleDefinitionsPart();
style = stylesPart.getStyleById(lvl.getPStyle().getVal());

} else {
// use propertyResolver
style = propertyResolver.getStyle( lvl.getPStyle().getVal() );
}

if (style==null) {
log.error("Couldn't find style " + lvl.getPStyle().getVal());
log.warn("Couldn't find style " + lvl.getPStyle().getVal());
return null;
} else {
log.debug(".. found it");
}

// If the style has a w:ind, return it.
Expand Down

0 comments on commit 230f34f

Please sign in to comment.