Bug in parser used to generate report

View: New views
6 Messages — Rating Filter:   Alert me  

Bug in parser used to generate report

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Trying to generate this report:

    <target name="alternate-coverage-report">
        <cobertura-report destdir="${coverage.html.dir}">
            <fileset dir="${main.dir}">
                <include name="**/*.java"/>
            </fileset>
            <fileset dir="${test.dir}">
                <include name="**/*.java"/>
            </fileset>
        </cobertura-report>
    </target>

with code that looks like this:

    private static final Field getField(
        final Class<?> declaringClass, final String fieldName) throws
NoSuchFieldException
    {
        if (declaringClass == null)
        {
            throw new IllegalArgumentException("Null declaring
class");
        }

        if (fieldName == null)
        {
            throw new IllegalArgumentException("Null field name");
        }

        Class<?> currentClass = declaringClass;
        Field field = null;

        while (currentClass != null)
        {
            try
            {
                field = currentClass.getDeclaredField(fieldName);
                field.setAccessible(true);
                break;
            }
            catch (final Throwable e)
            {
                currentClass = currentClass.getSuperclass();
            }
        }

        if (field == null)
        {
            throw new NoSuchFieldException(
                "Unable to find field '" + fieldName + "' on " +
                declaringClass.getCanonicalName() + " or its parent
classes");
        }

        return field;
    }

    public static final <T> T getField(
        final Object target, final String name) throws
IllegalArgumentException, RuntimeException
    {
        if (target == null)
        {
            throw new IllegalArgumentException("Null target");
        }

        Field field = null;
        T result = null;

        try
        {
            field = getField(target.getClass(), name);
            @SuppressWarnings("unchecked")
            final T resultUnchecked = (T)field.get(target);
            result = resultUnchecked;
        }
        catch (final Throwable e)
        {
            throwRuntimeException(e);
        }

        return result;
    }

results in the errors below.

To fix it, the @SuppressWarnings has to be moved to the method
declaration instead of on the assignment, which is undesirable because
it increases the scope to which the suppress applies. Or, the final
has to be removed from "final T resultUnchecked", which is unfortunate
because the final keyword is there for a reason (it's our coding
standard).

I'd like not to have to modify the code to get the reports to
generate.

alternate-coverage-report:
[cobertura-report] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) -
See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 76 classes.
[cobertura-report] Javancss.<init>(InputStream).e:
net.sourceforge.cobertura.javancss.ParseException: Encountered "final
T resultUnchecked =" at line 586, column 13.
[cobertura-report] Was expecting one of:
[cobertura-report]     "assert" ...
[cobertura-report]     "boolean" ...
[cobertura-report]     "byte" ...
[cobertura-report]     "char" ...
[cobertura-report]     "double" ...
[cobertura-report]     "enum" ...
[cobertura-report]     "float" ...
[cobertura-report]     "int" ...
[cobertura-report]     "long" ...
[cobertura-report]     "short" ...
[cobertura-report]     <IDENTIFIER> ...
[cobertura-report]     "public" ...
[cobertura-report]     "static" ...
[cobertura-report]     "protected" ...
[cobertura-report]     "private" ...
[cobertura-report]     "final" "public" ...
[cobertura-report]     "final" "static" ...
[cobertura-report]     "final" "protected" ...
[cobertura-report]     "final" "private" ...
[cobertura-report]     "final" "final" ...
[cobertura-report]     "final" "abstract" ...
[cobertura-report]     "final" "synchronized" ...
[cobertura-report]     "final" "native" ...
[cobertura-report]     "final" "transient" ...
[cobertura-report]     "final" "volatile" ...
[cobertura-report]     "final" "strictfp" ...
[cobertura-report]     "final" "@" ...
[cobertura-report]     "final" "boolean" ...
[cobertura-report]     "final" "char" ...
[cobertura-report]     "final" "byte" ...
[cobertura-report]     "final" "short" ...
[cobertura-report]     "final" "int" ...
[cobertura-report]     "final" "long" ...
[cobertura-report]     "final" "float" ...
[cobertura-report]     "final" "double" ...
[cobertura-report]     "final" "enum" ...
[cobertura-report]     "final" <IDENTIFIER> "." ...
[cobertura-report]     "final" <IDENTIFIER> "<" ...
[cobertura-report]     "final" <IDENTIFIER> "[" ...
[cobertura-report]     "final" <IDENTIFIER> "enum" ...
[cobertura-report]     "final" <IDENTIFIER> <IDENTIFIER> ";" ...
[cobertura-report]     "final" <IDENTIFIER> <IDENTIFIER> "=" ...
[cobertura-report]
[cobertura-report] WARN   getAccumlatedCCNForSource, JavaNCSS got an
error while parsing the java file C:\Documents and Settings\Jim\My
Stuff\Eclipse\AntScripts\src\main\java\com\jimandlisa\testutils\ReflectionUtils.java
[cobertura-report] ParseException in STDIN
[cobertura-report] Last useful checkpoint:
"com.jimandlisa.testutils.ReflectionUtils.getField(Object,String)"
[cobertura-report] Encountered "final T resultUnchecked =" at line
586, column 13.
[cobertura-report] Was expecting one of:
[cobertura-report]     "assert" ...
[cobertura-report]     "boolean" ...
[cobertura-report]     "byte" ...
[cobertura-report]     "char" ...
[cobertura-report]     "double" ...
[cobertura-report]     "enum" ...
[cobertura-report]     "float" ...
[cobertura-report]     "int" ...
[cobertura-report]     "long" ...
[cobertura-report]     "short" ...
[cobertura-report]     <IDENTIFIER> ...
[cobertura-report]     "public" ...
[cobertura-report]     "static" ...
[cobertura-report]     "protected" ...
[cobertura-report]     "private" ...
[cobertura-report]     "final" "public" ...
[cobertura-report]     "final" "static" ...
[cobertura-report]     "final" "protected" ...
[cobertura-report]     "final" "private" ...
[cobertura-report]     "final" "final" ...
[cobertura-report]     "final" "abstract" ...
[cobertura-report]     "final" "synchronized" ...
[cobertura-report]     "final" "native" ...
[cobertura-report]     "final" "transient" ...
[cobertura-report]     "final" "volatile" ...
[cobertura-report]     "final" "strictfp" ...
[cobertura-report]     "final" "@" ...
[cobertura-report]     "final" "boolean" ...
[cobertura-report]     "final" "char" ...
[cobertura-report]     "final" "byte" ...
[cobertura-report]     "final" "short" ...
[cobertura-report]     "final" "int" ...
[cobertura-report]     "final" "long" ...
[cobertura-report]     "final" "float" ...
[cobertura-report]     "final" "double" ...
[cobertura-report]     "final" "enum" ...
[cobertura-report]     "final" <IDENTIFIER> "." ...
[cobertura-report]     "final" <IDENTIFIER> "<" ...
[cobertura-report]     "final" <IDENTIFIER> "[" ...
[cobertura-report]     "final" <IDENTIFIER> "enum" ...
[cobertura-report]     "final" <IDENTIFIER> <IDENTIFIER> ";" ...
[cobertura-report]     "final" <IDENTIFIER> <IDENTIFIER> "=" ...
[cobertura-report]
[cobertura-report] Report time: 1578ms

---------------------------------

Jim Showalter
http://jimshowalter.blogspot.com 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Summary of problems

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

After the various emails I sent this weekend, there are just two
problems requiring attention:

1) I need fork="no", but when I do that then the .ser file seems to be
overwritten or lost, because coverage is always 0%. Attempts to
specify the .ser location to the ant junit task per the FAQ's
suggestion have not succeeded--an example of how to do it would be
nice. This is blocking us from getting 100% coverage (it literally
means one conditional is not evaluating to both true and false during
testing). I would really appreciate help with this one.

2) Putting @SuppressWarnings("unchecked") on an assignment to a final
variable of a generic type (for example, of type T) causes the parser
to die with an erro when generating the alternate coverage report.
Moving the annotation to the enclosing method's signature fixes the
problem, but doing that increases the scope in which the warnings are
suppressed, which is undesirable. Removing the final keyword is not an
option (for us). I can file this as a bug if that's the correct
procedure.

---------------------------------

Jim Showalter
http://jimshowalter.blogspot.com 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Evaluation of coverage tools

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I posted an evaluation of coverage tools you might be interested in,
because Cobertura came out on top!

http://jimshowalter.blogspot.com/2009/08/selecting-coverage-tool.html

---------------------------------

Jim Showalter
http://jimshowalter.blogspot.com 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: Summary of problems

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can someone please respond to the two problems below?

----- Original Message -----
From: "Jim Showalter" <jim@...>
To: <cobertura-devel@...>
Sent: Sunday, August 30, 2009 7:14 PM
Subject: [Cobertura-devel] Summary of problems


> After the various emails I sent this weekend, there are just two
> problems requiring attention:
>
> 1) I need fork="no", but when I do that then the .ser file seems to
> be
> overwritten or lost, because coverage is always 0%. Attempts to
> specify the .ser location to the ant junit task per the FAQ's
> suggestion have not succeeded--an example of how to do it would be
> nice. This is blocking us from getting 100% coverage (it literally
> means one conditional is not evaluating to both true and false
> during
> testing). I would really appreciate help with this one.
>
> 2) Putting @SuppressWarnings("unchecked") on an assignment to a
> final
> variable of a generic type (for example, of type T) causes the
> parser
> to die with an erro when generating the alternate coverage report.
> Moving the annotation to the enclosing method's signature fixes the
> problem, but doing that increases the scope in which the warnings
> are
> suppressed, which is undesirable. Removing the final keyword is not
> an
> option (for us). I can file this as a bug if that's the correct
> procedure.
>
> ---------------------------------
>
> Jim Showalter
> http://jimshowalter.blogspot.com
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Cobertura-devel mailing list
> Cobertura-devel@...
> https://lists.sourceforge.net/lists/listinfo/cobertura-devel 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

The maven2 Cobertura plugin is still using the older Cobertura that has the parse error

by Jim Showalter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

[INFO] [cobertura:cobertura {execution: default-cli}]
[INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT
file
Cobertura: Loaded information on 6 classes.
Javancss.<init>(InputStream).e:
net.sourceforge.cobertura.javancss.ParseException: Encountered "final
T resultUnchecked =" at line 191, column 13.
Was expecting one of:
    "assert" ...
    "boolean" ...
    "byte" ...
    "char" ...
    "double" ...
    "enum" ...
    "float" ...
    "int" ...
    "long" ...
    "short" ...
    <IDENTIFIER> ...
    "public" ...
    "static" ...
    "protected" ...
    "private" ...
    "final" "public" ...
    "final" "static" ...
    "final" "protected" ...
    "final" "private" ...
    "final" "final" ...
    "final" "abstract" ...
    "final" "synchronized" ...
    "final" "native" ...
    "final" "transient" ...
    "final" "volatile" ...
    "final" "strictfp" ...
    "final" "@" ...
    "final" "boolean" ...
    "final" "char" ...
    "final" "byte" ...
    "final" "short" ...
    "final" "int" ...
    "final" "long" ...
    "final" "float" ...
    "final" "double" ...
    "final" "enum" ...
    "final" <IDENTIFIER> "." ...
    "final" <IDENTIFIER> "<" ...
    "final" <IDENTIFIER> "[" ...
    "final" <IDENTIFIER> "enum" ...
    "final" <IDENTIFIER> <IDENTIFIER> ";" ...
    "final" <IDENTIFIER> <IDENTIFIER> "=" ...


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel

Re: The maven2 Cobertura plugin is still using the older Cobertura that has the parse error

by John W. Lewis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The Maven plugin is actually maintained by another group.

http://mojo.codehaus.org/cobertura-maven-plugin/



-----Original Message-----
From: Jim Showalter [mailto:jim@...]
Sent: Sunday, September 27, 2009 4:44 PM
To: cobertura-devel@...
Subject: [Cobertura-devel] The maven2 Cobertura plugin is still using the older Cobertura that has the parse error

[INFO] [cobertura:cobertura {execution: default-cli}]
[INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT
file
Cobertura: Loaded information on 6 classes.
Javancss.<init>(InputStream).e:
net.sourceforge.cobertura.javancss.ParseException: Encountered "final
T resultUnchecked =" at line 191, column 13.
Was expecting one of:
    "assert" ...
    "boolean" ...
    "byte" ...
    "char" ...
    "double" ...
    "enum" ...
    "float" ...
    "int" ...
    "long" ...
    "short" ...
    <IDENTIFIER> ...
    "public" ...
    "static" ...
    "protected" ...
    "private" ...
    "final" "public" ...
    "final" "static" ...
    "final" "protected" ...
    "final" "private" ...
    "final" "final" ...
    "final" "abstract" ...
    "final" "synchronized" ...
    "final" "native" ...
    "final" "transient" ...
    "final" "volatile" ...
    "final" "strictfp" ...
    "final" "@" ...
    "final" "boolean" ...
    "final" "char" ...
    "final" "byte" ...
    "final" "short" ...
    "final" "int" ...
    "final" "long" ...
    "final" "float" ...
    "final" "double" ...
    "final" "enum" ...
    "final" <IDENTIFIER> "." ...
    "final" <IDENTIFIER> "<" ...
    "final" <IDENTIFIER> "[" ...
    "final" <IDENTIFIER> "enum" ...
    "final" <IDENTIFIER> <IDENTIFIER> ";" ...
    "final" <IDENTIFIER> <IDENTIFIER> "=" ...


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Cobertura-devel mailing list
Cobertura-devel@...
https://lists.sourceforge.net/lists/listinfo/cobertura-devel