Skip to content

Commit 414366a

Browse files
committed
// TODO: resource loading using ResourceBundle.getBundle throws error
when looking for format java.class // TODO: need real Class object Foo.class, not just Foo itself -- see Test_Class.java // BH 8/30/2017 -- all i/o working, including printf and FileOutputStream
1 parent 8decacc commit 414366a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test;
2+
3+
import java.io.IOException;
4+
import java.util.Properties;
5+
6+
public class Test_Resource {
7+
8+
static int getInt() {
9+
return 0;
10+
}
11+
12+
public static void main(String[] args) {
13+
Properties p = new Properties();
14+
try {
15+
Class<?> c = test.Test_Resource.class;
16+
p.load(c.getResourceAsStream("test.properties"));
17+
String test = p.getProperty("test");
18+
System.out.println("OK".equals(test));
19+
} catch (IOException e) {
20+
System.out.println(e);
21+
}
22+
}
23+
24+
}

sources/net.sf.j2s.java.core/src/java/util/ResourceBundle.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,33 @@ public ResourceBundle newBundle(String baseName, Locale locale,
25382538
return bundle;
25392539
}
25402540

2541-
private ResourceBundle newPropertyBundle(InputStream stream) throws IOException {
2541+
/**
2542+
* Gets a resource bundle using the specified base name, the default locale,
2543+
* and the caller's class loader. Calling this method is equivalent to calling
2544+
* <blockquote>
2545+
* <code>getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader())</code>,
2546+
* </blockquote>
2547+
* except that <code>getClassLoader()</code> is run with the security
2548+
* privileges of <code>ResourceBundle</code>.
2549+
* See {@link #getBundle(String, Locale, ClassLoader) getBundle}
2550+
* for a complete description of the search and instantiation strategy.
2551+
*
2552+
* @param baseName the base name of the resource bundle, a fully qualified class name
2553+
* @exception java.lang.NullPointerException
2554+
* if <code>baseName</code> is <code>null</code>
2555+
* @exception MissingResourceException
2556+
* if no resource bundle for the specified base name can be found
2557+
* @return a resource bundle for the given base name and the default locale
2558+
*/
2559+
public static final ResourceBundle getBundle(String baseName)
2560+
{
2561+
return getBundleImpl(baseName, Locale.getDefault(), null,
2562+
/* must determine loader here, else we break stack invariant */
2563+
// getLoader(),
2564+
Control.INSTANCE);
2565+
}
2566+
2567+
private ResourceBundle newPropertyBundle(InputStream stream) throws IOException {
25422568
return ((PropertyResourceBundle)Interface.getInstance("java.util.PropertyResourceBundle", false))
25432569
.setStream(stream);
25442570
}

0 commit comments

Comments
 (0)