zalando / faux-pas Goto Github PK
View Code? Open in Web Editor NEWA library that simplifies error handling for Functional Programming in Java
License: MIT License
A library that simplifies error handling for Functional Programming in Java
License: MIT License
Using this method to handle only specific exceptions requires to rethrow the original exception in a somewhat weird pattern:
throw e instanceof CompletionException ? (CompletionException) e : new CompletionException(e);
In addition, as usual, the functional interfaces from the JDK only allow to throw unchecked exceptions. Both issues could be supported by some utility higher-order function.
This is likely a bug in the OpenJDK, but I wanted to report it first here to see if you could give me a more definitive direction to investigate further, as well as indicate a workaround.
I'm using org.zalando.faux-pas.0.8.0
with OpenJDK 11 on Windows 10:
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)
I have a section of code that looks like this. Note that it has nested FauxPas throwingFunction()
, although I don't know if the nesting has anything to do with it.
//look for a per-page navigation definition file in the form `.filename.ext.navigation.*`
final Optional<Stream<NavigationItem>> pageNavigationDefinition = pageFilename.flatMap(throwingFunction(filename -> {
final Set<String> navigationFilenames = SUPPORTED_NAVIGATION_FILE_EXTENSIONS.stream()
.map(ext -> addExtension(DOTFILE_PREFIX + filename + navigationBaseName, ext)).collect(toCollection(LinkedHashSet::new));
return findAncestorFileByName(sourceDirectory, navigationFilenames, Files::isRegularFile, sourceDirectory)
.map(throwingFunction(file -> loadNavigationFile(context, contextArtifact, file)));
}));
That compiles just fine on Eclipse 2019-12 (4.14.0). But on AdoptOpenJDK I get this:
unreported exception java.io.IOException; must be caught or declared to be thrown
This error refers to the following line from the code above, because loadNavigationFile()
throws an IOException
.
.map(throwingFunction(file -> loadNavigationFile(context, contextArtifact, file)));
This same problem occurs in another location, inside a throwingFunction()
that is wrapped in a throwingSupplier()
.
Should this code be allowed? Which is correct here: the Eclipse compiler or the OpenJDK compiler?
And do you know of a workaround, apart from splitting the code sections out and making the stream logic harder to read?
Maybe have to set the thread interrupted flag again.
public static <T extends Throwable, R> Function<Throwable, R> partially(final Class<T> type, final ThrowingFunction<T, R, Throwable> function) {
return partially(e -> {
if (type.isInstance(e)) {
return function.apply(type.cast(e));
}
throw e;
});
}
RuntimeException::new
It just adds complexity and I've yet to see a real use case.
throwing-function
was released/published in February 2016, half a year before the first release of faux-pas
faux-pas
:
throwing-function
:
This project seems to be heavily-inspired by throwing-function and doesn't comply with the license
The faux-pas
project should be compliant with the license and not be a faux pas.
The faux-pas
project is not compliant with the license and is a faux pas.
I can think of at least two solutions:
There are some conflict with apiguardian-api in some projects. Indeed the 0.8.0 version contains apiguardian-api 1.0.0 and the project problem-spring-web use that version and brings apiguardian-api 1.1.0 so the versions are not consistent with the one in the 0.8.0 of faux-pas (1.0.0).
Neither do the JDK-variants. It raises unnecessary warnings for implementations.
List of candidates from java.util.function
void tryWith(T, U, ThrowingBiConsumer<T, U, X>)
R tryWith(T, U, ThrowingBiFunction<T, U, R, X>)
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.