use of org.apache.poi.util.SuppressForbidden in project poi by apache.
the class SignatureFacet method brokenJvmWorkaround.
// helper method ... will be removed soon
public static void brokenJvmWorkaround(final Reference reference) {
final DigestMethod digestMethod = reference.getDigestMethod();
final String digestMethodUri = digestMethod.getAlgorithm();
final Provider bcProv = Security.getProvider("BC");
if (bcProv != null && !DigestMethod.SHA1.equals(digestMethodUri)) {
// workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1155012
// overwrite standard message digest, if a digest <> SHA1 is used
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
@SuppressForbidden("Workaround for a bug, needs access to private JDK members (may fail in Java 9): https://bugzilla.redhat.com/show_bug.cgi?id=1155012")
public Void run() {
try {
Method m = DOMDigestMethod.class.getDeclaredMethod("getMessageDigestAlgorithm");
m.setAccessible(true);
String mdAlgo = (String) m.invoke(digestMethod);
MessageDigest md = MessageDigest.getInstance(mdAlgo, bcProv);
Field f = DOMReference.class.getDeclaredField("md");
f.setAccessible(true);
f.set(reference, md);
} catch (Exception e) {
LOG.log(POILogger.WARN, "Can't overwrite message digest (workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1155012)", e);
}
// Void
return null;
}
});
}
}
use of org.apache.poi.util.SuppressForbidden in project poi by apache.
the class TestDataFormatter method setUpClass.
@BeforeClass
@SuppressForbidden
public static void setUpClass() {
// some pre-checks to hunt for a problem in the Maven build
// these checks ensure that the correct locale is set, so a failure here
// usually indicates an invalid locale during test-execution
assertFalse(DateUtil.isADateFormat(-1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
Locale ul = LocaleUtil.getUserLocale();
assertTrue(Locale.ROOT.equals(ul) || Locale.getDefault().equals(ul));
final String textValue = NumberToTextConverter.toText(1234.56);
assertEquals(-1, textValue.indexOf('E'));
Object cellValueO = Double.valueOf(1234.56);
/*CellFormat cellFormat = new CellFormat("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
CellFormatResult result = cellFormat.apply(cellValueO);
assertEquals(" 1,234.56 ", result.text);*/
CellFormat cfmt = CellFormat.getInstance("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
CellFormatResult result = cfmt.apply(cellValueO);
assertEquals("This failure can indicate that the wrong locale is used during test-execution, ensure you run with english/US via -Duser.language=en -Duser.country=US", " 1,234.56 ", result.text);
}
Aggregations