NobleUplift
NobleUplift

Reputation: 6025

How do I stop Java/Eclipse from bleeding stdout and stderr together?

So this is the output I'm getting in the program I'm working on:

java.lang.IllegalArgumentException: argument type mismatch
CreationDate
getCreationDate
setCreationDate
LastModifiedDate
getLastModifiedDate
setLastModifiedDate
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at Transform.transform(Transform.java:86)
    at Experiment.main(Experiment.java:120)
java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at Transform.transform(Transform.java:86)
    at Experiment.main(Experiment.java:120)
DeletionDate
getDeletionDate
setDeletionDate

The code calling it:

    for (Field f : databaseFields) {
        String upperCamelCase = Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1);
        System.out.println(upperCamelCase);

        String getMethodName = "get" + upperCamelCase;
        System.out.println(getMethodName);

        Method getMethod = null;
        try {
            getMethod = databaseClass.getDeclaredMethod(getMethodName);
        } catch (NoSuchMethodException e) { 
        } catch (SecurityException e) { }

        if (getMethod == null) {
            getMethodName = "is" + upperCamelCase;
            try {
                getMethod = databaseClass.getDeclaredMethod(getMethodName);
            } catch (NoSuchMethodException e) {
                continue;
            } catch (SecurityException e) {
                continue;
            }
        }

        String setMethodName = "set" + upperCamelCase;
        System.out.println(setMethodName);
        Method setMethod = null;
        for (int i = 0; i < parameterTypes.length; i++) {
            try {
                setMethod = jsonClass.getDeclaredMethod(setMethodName, parameterTypes[i]);
            } catch (NoSuchMethodException e) { }
        }

        if (setMethod == null) {
            continue;
        }

        try {
            setMethod.invoke(jsonObject, getMethod.invoke(databaseObject));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

This is for a reflection transform, and obviously I can't tell which of the get or set methods it's throwing an exception on. How can I fix this?

Upvotes: 0

Views: 396

Answers (2)

greg-449
greg-449

Reputation: 111142

Call

System.out.flush();

after each println call to force the output to the console immediately.

Upvotes: 2

user3458
user3458

Reputation:

In Eclipse, stderr and stdout in Console are colored differently. You can also hide one or the other by right-clicking on console window and selecting Preferences.

In command line, you can use redirects > and 2> to send stderr or stdout to separate file.

Upvotes: 3

Related Questions