Skip to content

Probable bug in JsonOperationConsumer.getDefaultOutlineLevelFromStyleHierarchy #388

@xzel23

Description

@xzel23

Static analysis (yes, I'm actually working on that ticket too) showed that the method JsonOperationConsumer.getDefaultOutlineLevelFromStyleHierarchy() does either not work or is overly complex. Look at the comments I added in the following snippet:

  private static int getDefaultOutlineLevelFromStyleHierarchy(
      TextParagraphElementBase paragraphBaseElement) {
    OdfStyle style = paragraphBaseElement.getDocumentStyle();
    int outlineLevel = getStyleOutlineLevel(style);

    if (style != null) {
      // if no outline Level was set, but there is a parentComponentElement
      if (outlineLevel == NO_OUTLINE_LEVEL) { // <-- the if is only entered when outlineLevel == NO_OUTLINE_LEVEL
        OdfStyleBase parentStyle = null;
        style.getParentStyle();
        while (outlineLevel == NO_OUTLINE_LEVEL) { // <-- this condition is always true because outlineLevel is never updated
          outlineLevel = getStyleOutlineLevel(parentStyle); // <-- this will return the old value because parentStyle is null
          if (outlineLevel != NO_OUTLINE_LEVEL) {
            break;
          }
          if (parentStyle instanceof OdfStyle) { // <-- here, parentStyle is still null, so instanceOf will return false and parentStyle is not updated
            parentStyle = ((OdfStyle) parentStyle).getParentStyle();
          } else {
            break; // <-- this break will always be reached in the first iteration
          }
          if (parentStyle == null) {
            break;
          }
        }
      }
    }
    return outlineLevel;
  }

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions