-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimum set of classes so that SXSSFSheet can be constructed
This avoids exceptions when trying to initialize the Java Font System This fixes the test-item for issue 89
- Loading branch information
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
poishadow/src/main/java/org/apache/poi/java/awt/font/FontRenderContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.apache.poi.java.awt.font; | ||
|
||
import java.awt.geom.AffineTransform; | ||
|
||
public class FontRenderContext { | ||
public FontRenderContext(AffineTransform o, boolean a, boolean b) { | ||
//You can't crash here yet! If you do, a static field in SheetUtil will fail to load. | ||
//Then next time SheetUtil will have to be accessed, a NoClassDefFoundError("SheetUtil") | ||
//will be thrown! | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
poishadow/src/main/java/org/apache/poi/java/awt/font/TextLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.apache.poi.java.awt.font; | ||
|
||
import java.text.AttributedCharacterIterator; | ||
|
||
public class TextLayout { | ||
public TextLayout(AttributedCharacterIterator iterator, FontRenderContext fontRenderContext) { | ||
//This is called in: | ||
//SXSSFSheet.java:106 | ||
//AutoSizeColumnTracker.java:117 | ||
//SheetUtil.java:353 | ||
//This tricks SXSSFSheet constructor into not creating AutoSizeColumnTracker. | ||
throw new NoClassDefFoundError("X11FontManager"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
poishadow/src/main/java/org/apache/poi/java/awt/geom/AffineTransform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.apache.poi.java.awt.geom; | ||
|
||
import java.awt.font.FontRenderContext; | ||
|
||
/** | ||
* Just an empty class, so we can have a correct {@link FontRenderContext} constructor | ||
*/ | ||
public class AffineTransform { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d309159
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I'm the guy who proposed this workaround here: https://bz.apache.org/bugzilla/show_bug.cgi?id=69288#c4
I strongly encourage you to also improve
TestIssue89
test.The reason you can't throw in
FontRenderContext
is because it would work the first time, but not the second time:The second time
SXSSFSheet
would try to constructAutoSizeColumnTracker
, Java would throwNoClassDefFoundError("SheetUtil")
and the exception would have a causeNoClassDefFoundError("X11FontManager")
(the original exception).It's an interesting detail of how Java class loading works if a static field throws an exception.
The test is missing another call to create a new sheet. Just add this line:
d309159
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the note, added this to the test now