Skip to content

Commit 3d82515

Browse files
committed
removes javax.xml checks for JAR META-INF files
1 parent c7c5999 commit 3d82515

File tree

5 files changed

+228
-213
lines changed

5 files changed

+228
-213
lines changed

sources/net.sf.j2s.java.core/src/javax/xml/bind/ContextFinder.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,16 @@ public java.lang.Object run() {
601601
}
602602
}
603603

604-
// ServiceLoaderUtil.firstByServiceLoaderDeprecated should be used instead.
605-
@Deprecated
604+
// ServiceLoaderUtil.firstByServiceLoaderDeprecated should be used instead.
605+
@Deprecated
606606
static String firstByServiceLoaderDeprecated(Class spiClass,
607607
ClassLoader classLoader) throws JAXBException {
608-
608+
/**
609+
* @j2sNative
610+
*
611+
* return null;
612+
*/
613+
{
609614
final String jaxbContextFQCN = spiClass.getName();
610615

611616
//Logger.fine("Searching META-INF/services");
@@ -614,8 +619,7 @@ static String firstByServiceLoaderDeprecated(Class spiClass,
614619
BufferedReader r = null;
615620
final String resource = "META-INF/services/" + jaxbContextFQCN;
616621
try {
617-
final InputStream resourceStream =
618-
(classLoader == null) ?
622+
final InputStream resourceStream = (classLoader == null) ?
619623
ClassLoader.getSystemResourceAsStream(resource) :
620624
classLoader.getResourceAsStream(resource);
621625

@@ -643,6 +647,7 @@ static String firstByServiceLoaderDeprecated(Class spiClass,
643647
//Logger.log(Level.SEVERE, "Unable to close resource: " + resource, ex);
644648
}
645649
}
650+
}
646651
}
647652

648653
private static String jaxbProperties(String contextPath, ClassLoader classLoader, String factoryId) throws JAXBException {

sources/net.sf.j2s.java.core/src/javax/xml/datatype/FactoryFinder.java

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -231,74 +231,75 @@ static Object find(String factoryId, String fallbackClassName)
231231
return newInstance(fallbackClassName, null, true);
232232
}
233233

234-
/*
235-
* Try to find provider using Jar Service Provider Mechanism
236-
*
237-
* @return instance of provider class if found or null
238-
*/
239-
private static Object findJarServiceProvider(String factoryId)
240-
throws ConfigurationError
241-
{
242-
String serviceId = "META-INF/services/" + factoryId;
243-
InputStream is = null;
244-
245-
// First try the Context ClassLoader
246-
ClassLoader cl = ss.getContextClassLoader();
247-
if (cl != null) {
248-
is = ss.getResourceAsStream(cl, serviceId);
249-
250-
// If no provider found then try the current ClassLoader
251-
if (is == null) {
252-
cl = FactoryFinder.class.getClassLoader();
253-
is = ss.getResourceAsStream(cl, serviceId);
254-
}
255-
} else {
256-
// No Context ClassLoader, try the current ClassLoader
257-
cl = FactoryFinder.class.getClassLoader();
258-
is = ss.getResourceAsStream(cl, serviceId);
259-
}
260-
261-
if (is == null) {
262-
// No provider found
263-
return null;
264-
}
265-
266-
if (debug) { // Extra check to avoid computing cl strings
267-
dPrint("found jar resource=" + serviceId + " using ClassLoader: " + cl);
268-
}
269-
270-
BufferedReader rd;
271-
try {
272-
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
273-
}
274-
catch (java.io.UnsupportedEncodingException e) {
275-
rd = new BufferedReader(new InputStreamReader(is));
276-
}
277-
278-
String factoryClassName = null;
279-
try {
280-
// XXX Does not handle all possible input as specified by the
281-
// Jar Service Provider specification
282-
factoryClassName = rd.readLine();
283-
rd.close();
284-
} catch (IOException x) {
285-
// No provider found
286-
return null;
287-
}
288-
289-
if (factoryClassName != null && !"".equals(factoryClassName)) {
290-
dPrint("found in resource, value=" + factoryClassName);
291-
292-
// Note: here we do not want to fall back to the current
293-
// ClassLoader because we want to avoid the case where the
294-
// resource file was found using one ClassLoader and the
295-
// provider class was instantiated using a different one.
296-
return newInstance(factoryClassName, cl, false);
297-
}
298-
299-
// No provider found
300-
return null;
301-
}
234+
/*
235+
* Try to find provider using Jar Service Provider Mechanism
236+
*
237+
* @return instance of provider class if found or null
238+
*/
239+
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError {
240+
/**
241+
* @j2sIgnore
242+
*/
243+
{
244+
String serviceId = "META-INF/services/" + factoryId;
245+
InputStream is = null;
246+
247+
// First try the Context ClassLoader
248+
ClassLoader cl = ss.getContextClassLoader();
249+
if (cl != null) {
250+
is = ss.getResourceAsStream(cl, serviceId);
251+
252+
// If no provider found then try the current ClassLoader
253+
if (is == null) {
254+
cl = FactoryFinder.class.getClassLoader();
255+
is = ss.getResourceAsStream(cl, serviceId);
256+
}
257+
} else {
258+
// No Context ClassLoader, try the current ClassLoader
259+
cl = FactoryFinder.class.getClassLoader();
260+
is = ss.getResourceAsStream(cl, serviceId);
261+
}
262+
263+
if (is == null) {
264+
// No provider found
265+
return null;
266+
}
267+
268+
if (debug) { // Extra check to avoid computing cl strings
269+
dPrint("found jar resource=" + serviceId + " using ClassLoader: " + cl);
270+
}
271+
272+
BufferedReader rd;
273+
try {
274+
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
275+
} catch (java.io.UnsupportedEncodingException e) {
276+
rd = new BufferedReader(new InputStreamReader(is));
277+
}
278+
279+
String factoryClassName = null;
280+
try {
281+
// XXX Does not handle all possible input as specified by the
282+
// Jar Service Provider specification
283+
factoryClassName = rd.readLine();
284+
rd.close();
285+
} catch (IOException x) {
286+
// No provider found
287+
return null;
288+
}
289+
290+
if (factoryClassName != null && !"".equals(factoryClassName)) {
291+
dPrint("found in resource, value=" + factoryClassName);
292+
293+
// Note: here we do not want to fall back to the current
294+
// ClassLoader because we want to avoid the case where the
295+
// resource file was found using one ClassLoader and the
296+
// provider class was instantiated using a different one.
297+
return newInstance(factoryClassName, cl, false);
298+
}
299+
}
300+
// No provider found
301+
return null;
302+
}
302303

303304
static class ConfigurationError extends Error {
304305
private Exception exception;

sources/net.sf.j2s.java.core/src/javax/xml/parsers/FactoryFinder.java

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -257,77 +257,79 @@ static Object find(String factoryId, String fallbackClassName)
257257
return newInstance(fallbackClassName, null, true);
258258
}
259259

260-
/*
261-
* Try to find provider using Jar Service Provider Mechanism
262-
*
263-
* @return instance of provider class if found or null
264-
*/
265-
private static Object findJarServiceProvider(String factoryId)
266-
throws ConfigurationError
267-
{
268-
String serviceId = "META-INF/services/" + factoryId;
269-
InputStream is = null;
270-
271-
// First try the Context ClassLoader
272-
ClassLoader cl = ss.getContextClassLoader();
273-
boolean useBSClsLoader = false;
274-
if (cl != null) {
275-
is = ss.getResourceAsStream(cl, serviceId);
276-
277-
// If no provider found then try the current ClassLoader
278-
if (is == null) {
279-
cl = FactoryFinder.class.getClassLoader();
280-
is = ss.getResourceAsStream(cl, serviceId);
281-
useBSClsLoader = true;
282-
}
283-
} else {
284-
// No Context ClassLoader, try the current ClassLoader
285-
cl = FactoryFinder.class.getClassLoader();
286-
is = ss.getResourceAsStream(cl, serviceId);
287-
useBSClsLoader = true;
288-
}
289-
290-
if (is == null) {
291-
// No provider found
292-
return null;
293-
}
294-
295-
if (debug) { // Extra check to avoid computing cl strings
296-
dPrint("found jar resource=" + serviceId + " using ClassLoader: " + cl);
297-
}
298-
299-
BufferedReader rd;
300-
try {
301-
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
302-
}
303-
catch (java.io.UnsupportedEncodingException e) {
304-
rd = new BufferedReader(new InputStreamReader(is));
305-
}
306-
307-
String factoryClassName = null;
308-
try {
309-
// XXX Does not handle all possible input as specified by the
310-
// Jar Service Provider specification
311-
factoryClassName = rd.readLine();
312-
rd.close();
313-
} catch (IOException x) {
314-
// No provider found
315-
return null;
316-
}
317-
318-
if (factoryClassName != null && !"".equals(factoryClassName)) {
319-
dPrint("found in resource, value=" + factoryClassName);
320-
321-
// Note: here we do not want to fall back to the current
322-
// ClassLoader because we want to avoid the case where the
323-
// resource file was found using one ClassLoader and the
324-
// provider class was instantiated using a different one.
325-
return newInstance(factoryClassName, cl, false, useBSClsLoader);
326-
}
327-
328-
// No provider found
329-
return null;
330-
}
260+
/*
261+
* Try to find provider using Jar Service Provider Mechanism
262+
*
263+
* @return instance of provider class if found or null
264+
*/
265+
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError {
266+
/**
267+
* @j2sIgnore
268+
*/
269+
{
270+
String serviceId = "META-INF/services/" + factoryId;
271+
InputStream is = null;
272+
273+
// First try the Context ClassLoader
274+
ClassLoader cl = ss.getContextClassLoader();
275+
boolean useBSClsLoader = false;
276+
if (cl != null) {
277+
is = ss.getResourceAsStream(cl, serviceId);
278+
279+
// If no provider found then try the current ClassLoader
280+
if (is == null) {
281+
cl = FactoryFinder.class.getClassLoader();
282+
is = ss.getResourceAsStream(cl, serviceId);
283+
useBSClsLoader = true;
284+
}
285+
} else {
286+
// No Context ClassLoader, try the current ClassLoader
287+
cl = FactoryFinder.class.getClassLoader();
288+
is = ss.getResourceAsStream(cl, serviceId);
289+
useBSClsLoader = true;
290+
}
291+
292+
if (is == null) {
293+
// No provider found
294+
return null;
295+
}
296+
297+
if (debug) { // Extra check to avoid computing cl strings
298+
dPrint("found jar resource=" + serviceId + " using ClassLoader: " + cl);
299+
}
300+
301+
BufferedReader rd;
302+
try {
303+
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
304+
} catch (java.io.UnsupportedEncodingException e) {
305+
rd = new BufferedReader(new InputStreamReader(is));
306+
}
307+
308+
String factoryClassName = null;
309+
try {
310+
// XXX Does not handle all possible input as specified by the
311+
// Jar Service Provider specification
312+
factoryClassName = rd.readLine();
313+
rd.close();
314+
} catch (IOException x) {
315+
// No provider found
316+
return null;
317+
}
318+
319+
if (factoryClassName != null && !"".equals(factoryClassName)) {
320+
dPrint("found in resource, value=" + factoryClassName);
321+
322+
// Note: here we do not want to fall back to the current
323+
// ClassLoader because we want to avoid the case where the
324+
// resource file was found using one ClassLoader and the
325+
// provider class was instantiated using a different one.
326+
return newInstance(factoryClassName, cl, false, useBSClsLoader);
327+
}
328+
329+
// No provider found
330+
}
331+
return null;
332+
}
331333

332334
static class ConfigurationError extends Error {
333335
private Exception exception;

sources/net.sf.j2s.java.core/src/javax/xml/sax/helpers/XMLReaderFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public static XMLReader createXMLReader ()
113113
catch (RuntimeException e) { /* normally fails for applets */ }
114114

115115
// 2. if that fails, try META-INF/services/
116+
/**
117+
* @j2sIgnore
118+
*
119+
*/
120+
{
116121
if (className == null) {
117122
try {
118123
String service = "META-INF/services/" + property;
@@ -133,7 +138,7 @@ public static XMLReader createXMLReader ()
133138
} catch (Exception e) {
134139
}
135140
}
136-
141+
}
137142
// 3. Distro-specific fallback
138143
if (className == null) {
139144
// BEGIN DISTRIBUTION-SPECIFIC

0 commit comments

Comments
 (0)