--- old/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2011-06-22 18:39:51.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java 2011-06-22 18:39:51.000000000 -0700 @@ -295,59 +295,24 @@ /** * Use a service loader appropriate for the platform to provide an - * iterator over annotations processors. If - * java.util.ServiceLoader is present use it, otherwise, use - * sun.misc.Service, otherwise fail if a loader is needed. + * iterator over annotations processors; fails if a loader is + * needed but unavailable. */ private class ServiceIterator implements Iterator { - // The to-be-wrapped iterator. - private Iterator iterator; + private Iterator iterator; private Log log; - private Class loaderClass; - private boolean jusl; - private Object loader; + private ServiceLoader loader; ServiceIterator(ClassLoader classLoader, Log log) { - String loadMethodName; - this.log = log; try { try { - loaderClass = Class.forName("java.util.ServiceLoader"); - loadMethodName = "load"; - jusl = true; - } catch (ClassNotFoundException cnfe) { - try { - loaderClass = Class.forName("sun.misc.Service"); - loadMethodName = "providers"; - jusl = false; - } catch (ClassNotFoundException cnfe2) { - // Fail softly if a loader is not actually needed. - this.iterator = handleServiceLoaderUnavailability("proc.no.service", - null); - return; - } - } - - // java.util.ServiceLoader.load or sun.misc.Service.providers - Method loadMethod = loaderClass.getMethod(loadMethodName, - Class.class, - ClassLoader.class); - - Object result = loadMethod.invoke(null, - Processor.class, - classLoader); - - // For java.util.ServiceLoader, we have to call another - // method to get the iterator. - if (jusl) { - loader = result; // Store ServiceLoader to call reload later - Method m = loaderClass.getMethod("iterator"); - result = m.invoke(result); // serviceLoader.iterator(); + loader = ServiceLoader.load(Processor.class, classLoader); + this.iterator = loader.iterator(); + } catch (Exception e) { + // Fail softly if a loader is not actually needed. + this.iterator = handleServiceLoaderUnavailability("proc.no.service", null); } - - // The result should now be an iterator. - this.iterator = (Iterator) result; } catch (Throwable t) { log.error("proc.service.problem"); throw new Abort(t); @@ -357,25 +322,21 @@ public boolean hasNext() { try { return iterator.hasNext(); + } catch(ServiceConfigurationError sce) { + log.error("proc.bad.config.file", sce.getLocalizedMessage()); + throw new Abort(sce); } catch (Throwable t) { - if ("ServiceConfigurationError". - equals(t.getClass().getSimpleName())) { - log.error("proc.bad.config.file", t.getLocalizedMessage()); - } throw new Abort(t); } } public Processor next() { try { - return (Processor)(iterator.next()); + return iterator.next(); + } catch (ServiceConfigurationError sce) { + log.error("proc.bad.config.file", sce.getLocalizedMessage()); + throw new Abort(sce); } catch (Throwable t) { - if ("ServiceConfigurationError". - equals(t.getClass().getSimpleName())) { - log.error("proc.bad.config.file", t.getLocalizedMessage()); - } else { - log.error("proc.processor.constructor.error", t.getLocalizedMessage()); - } throw new Abort(t); } } @@ -385,11 +346,9 @@ } public void close() { - if (jusl) { + if (loader != null) { try { - // Call java.util.ServiceLoader.reload - Method reloadMethod = loaderClass.getMethod("reload"); - reloadMethod.invoke(loader); + loader.reload(); } catch(Exception e) { ; // Ignore problems during a call to reload. } --- old/src/share/classes/com/sun/tools/javac/resources/compiler.properties 2011-06-22 18:39:52.000000000 -0700 +++ new/src/share/classes/com/sun/tools/javac/resources/compiler.properties 2011-06-22 18:39:52.000000000 -0700 @@ -638,7 +638,7 @@ compiler.err.proc.no.service=\ A service loader class could not be found.\n\ - Either java.util.ServiceLoader or sun.misc.Service must be available. + The java.util.ServiceLoader class must be usable. compiler.err.proc.processor.bad.option.name=\ Bad option name ''{0}'' provided by processor ''{1}'' @@ -647,9 +647,6 @@ compiler.err.proc.processor.cant.instantiate=\ Could not instantiate an instance of processor ''{0}'' -compiler.err.proc.processor.constructor.error=\ - Exception thrown while constructing Processor object: {0} - # 0: string compiler.err.proc.processor.not.found=\ Annotation processor ''{0}'' not found --- old/test/tools/javac/diags/examples.not-yet.txt 2011-06-22 18:39:52.000000000 -0700 +++ new/test/tools/javac/diags/examples.not-yet.txt 2011-06-22 18:39:52.000000000 -0700 @@ -31,7 +31,6 @@ compiler.err.proc.cant.create.loader # security exception from service loader compiler.err.proc.no.service # JavacProcessingEnvironment: no service loader available compiler.err.proc.processor.bad.option.name # cannot happen? masked by javac.err.invalid.A.key -compiler.err.proc.processor.constructor.error compiler.err.proc.service.problem # JavacProcessingEnvironment: catch Throwable from service loader compiler.err.signature.doesnt.match.intf # UNUSED compiler.err.signature.doesnt.match.supertype # UNUSED