~java-gnome/java-gnome/mainline

« back to all changes in this revision

Viewing changes to src/bindings/org/freedesktop/bindings/Plumbing.java

  • Committer: Andrew Cowie
  • Date: 2011-07-02 04:11:35 UTC
  • Revision ID: andrew@operationaldynamics.com-20110702041135-3ue48sr5k7wrcr6n
Better Exception when determining native library location

Eliminate NullPointerException within library loading logic. While a
not found exception leading to the catch block is acceptable, we were
actually hiting null pointer unnecessarily, which was showing up when
users of the library were trying to debug such problems much later in
their own code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
import java.io.BufferedReader;
36
36
import java.io.File;
 
37
import java.io.FileNotFoundException;
 
38
import java.io.InputStream;
37
39
import java.io.InputStreamReader;
38
40
import java.io.UnsupportedEncodingException;
39
41
import java.lang.ref.WeakReference;
157
159
     * what we want.
158
160
     */
159
161
    private static final void loadNativeCode() {
 
162
        final InputStream in;
160
163
        final BufferedReader reader;
161
164
        String libdir;
162
165
        final ProtectionDomain domain;
171
174
             * Attmept to load the .libdir file and use its contents as the
172
175
             * directory which we will load our shared library from.
173
176
             */
174
 
            reader = new BufferedReader(new InputStreamReader(loader.getResourceAsStream(LIBDIR_FILE)));
 
177
            in = loader.getResourceAsStream(LIBDIR_FILE);
 
178
            if (in == null) {
 
179
                throw new FileNotFoundException(); // ok
 
180
            }
 
181
            reader = new BufferedReader(new InputStreamReader(in));
175
182
            libdir = reader.readLine();
176
183
            reader.close();
177
184
        } catch (Exception e) {