Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.osgi.framework.*;

import javax.money.Monetary;
import javax.money.spi.ServiceProvider;
import java.net.URL;
import java.util.*;
Expand Down Expand Up @@ -97,7 +98,7 @@ public <T> List<T> getServices(Class<T> serviceType) {
LOG.log(Level.SEVERE, "could not create services of type: " + serviceType, e);
}
try{
for(T service:ServiceLoader.load(serviceType)){
for(T service:ServiceLoader.load(serviceType, Monetary.class.getClassLoader())){

@jwgmeligmeyling jwgmeligmeyling Jun 27, 2020 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if the Java Money implementation will always come from the same class loader as the API. Both classes should be resolvable from the context classloader. And yes, that may cause issues with parallel operations that are executed inside fork join pools. But won't this fix cause issues with deployments where the implementation lives in a separate module (in terms of OSGI or for example JBoss modules)? Or perhaps inside the application itself?

services.add(service);
}
return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.javamoney.moneta.spi;

import javax.annotation.Priority;
import javax.money.Monetary;
import javax.money.spi.ServiceProvider;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -95,7 +96,7 @@ public static int compareServices(Object o1, Object o2) {
private <T> List<T> loadServices(final Class<T> serviceType) {
List<T> services = new ArrayList<>();
try {
for (T t : ServiceLoader.load(serviceType)) {
for (T t : ServiceLoader.load(serviceType, Monetary.class.getClassLoader())) {
services.add(t);
}
services.sort(PriorityAwareServiceProvider::compareServices);
Expand Down