On Tuesday, July 2, 2019 at 9:25:10 AM UTC-4, Evgeny Mandrikov wrote:
> Hi,
>
> On Tuesday, July 2, 2019 at 3:12:52 PM UTC+2, [email protected] wrote:Hi
> all.
> I'm using try-with-resources and JaCoCo reports a large number of missed
> branches. I'm using JaCoCo version 0.8.2, which includes the JAVAC.TRYWITH
> filter. I understand that this filter is unconditionally on, but it doesn't
> seem to be working.
> A little research into the filter seems to indicate that this is for Java 11,
> and I'm using Java 8.
> Is this the reason I'm seeing the missed branches?
>
>
> No, this can't be the reason, because
> for javac versions from 7 to 10 we have
> https://github.com/jacoco/jacoco/blob/v0.8.2/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/TryWithResourcesJavacFilter.java
>
> for javac versions starting from 11 we have
> https://github.com/jacoco/jacoco/blob/v0.8.2/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/TryWithResourcesJavac11Filter.java
> for ecj we have
> https://github.com/jacoco/jacoco/blob/v0.8.2/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/TryWithResourcesEcjFilter.java
>
>
>
>
> In order to investigate please provide complete reproducer,
> or at least source file and corresponding class file.
>
> Thanks.
> -Mark
Interesting. Well, I'm not doing anything very surprising.
Here's a brief example (showing function only):
// The URL is to a file located on the classpath, and was obtained using:
// Thread.currentThread().getContextClassLoader().getResource(fileName);
//
private String loadResource(URL url) throws IOException {
StringBuilder builder = new StringBuilder();
try (Reader reader = new InputStreamReader(url.openStream())) {
int numRead;
char[] buf = new char[2048];
while((numRead = reader.read(buf)) != -1) {
builder.append(buf, 0, numRead);
}
}
return builder.toString();
}
The "try" line is highlighted yellow in the report, and the closing brace is
also highlighted yellow with a yellow diamond. Hovering over it with the mouse
reveals that "6 of 8 branches were missed".
Is this supposed to be ignored by the filter that is available for Java 7/8?
It seems to fall into the area of "code generated by compiler".
Also, I found it interesting that the lazy initialization via ResourceHolder
pattern shows lack of coverage. Here's a short example:
public class Foo {
private static class ResourceHolder {
private static final Foo INSTANCE = new Foo();
}
public static Foo getInstance() {
return ResourceHolder.INSTANCE;
}
// Remaining code not shown.
}
The line defining the class "ResourceHolder" is RED in the JaCoCo report.
Perhaps because there is a default constructor that does not get called?
Thanks. I hope this helps.
-Mark
--
You received this message because you are subscribed to the Google Groups
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jacoco/afc9bee9-c60d-4796-abe0-aacb38cbc276%40googlegroups.com.