Skip to content

Commit

Permalink
WINDUP-1701 FindUnboundJavaReferencesRuleProvider cannot find referen…
Browse files Browse the repository at this point in the history
…ce in Optional (#1209)

* WINDUP-1701 FindUnboundJavaReferencesRuleProvider cannot find reference in Optional

* WINDUP-1701 FindUnboundJavaReferencesRuleProvider: test fix
  • Loading branch information
mrizzi authored and mareknovotny committed Oct 19, 2017
1 parent 13d8ea9 commit e6a3496
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion decompiler/impl-fernflower/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>org.jboss.windup.decompiler.fernflower</groupId>
<artifactId>windup-fernflower</artifactId>
<version>1.0.0.20160505b</version>
<version>1.0.0.20171018</version>
</dependency>

<!-- Addon Dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private Map<String, Object> getOptions()
{
Map<String, Object> options = new HashMap<>();
options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 30);
options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1");
return options;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public void writeMessage(String s, Severity severity)
LOG.log(getLevel(severity), s);
}

@Override
public void writeMessage(String s, Severity severity, Throwable throwable)
{
if (s == null)
LOG.log(getLevel(severity), "Error decompiling due to: " + throwable.getMessage(), throwable);
else
LOG.log(getLevel(severity), s, throwable);
}

@Override
public void writeMessage(String s, Throwable throwable)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.jboss.windup.decompiler.fernflower;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import org.jboss.windup.decompiler.DecompilerTestBase;
Expand Down Expand Up @@ -98,4 +100,59 @@ public boolean isCancelled()

Assert.assertTrue(numberDecompiled.get() > 0);
}

@Test
public void testDecompileClassFileWithGeneric() throws DecompilationException, IOException
{
final Decompiler dec = this.getDecompiler();

Path decompDir = testTempDir.resolve("decompiled");

List<ClassDecompileRequest> requests = new ArrayList<>();
requests.add(new ClassDecompileRequest(Paths.get("src/test/resources/"), Paths.get("src/test/resources/ExampleClass.class"), decompDir));

final AtomicBoolean lineWithGenericFound = new AtomicBoolean(false);
final AtomicBoolean lineWithoutGenericFound = new AtomicBoolean(false);
DecompilationListener listener = new DecompilationListener()
{
@Override
public void fileDecompiled(List<String> inputPath, String outputPath)
{
Assert.assertNotNull("Results object was returned.", outputPath);
String content = "";
try
{
content = new String(Files.readAllBytes(Paths.get(outputPath)));
} catch (IOException ioe)
{
Assert.fail("Unable to open and read file " + outputPath);
}
lineWithGenericFound.set(content.contains("Optional<String> optional = list.stream().filter((str) ->"));
lineWithoutGenericFound.set(content.contains("Optional anotherOptional = list.stream().filter((str) ->"));
}

@Override
public void decompilationFailed(List<String> inputPath, String message)
{
System.out.println("Failed for input: " + inputPath + " due to: " + message);
}

@Override
public void decompilationProcessComplete()
{
System.out.println("Decompilation complete!");
}

@Override
public boolean isCancelled()
{
return false;
}
};
dec.decompileClassFiles(requests, listener);
dec.close();

Assert.assertTrue(lineWithGenericFound.get());
Assert.assertTrue(lineWithoutGenericFound.get());
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public Void call() throws Exception
options.put(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, "warning");
options.put(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, "warning");

parser.setCompilerOptions(options);

parser.setCompilerOptions(options);
parser.setEnvironment(libraryPaths.toArray(new String[libraryPaths.size()]),
sourcePaths.toArray(new String[sourcePaths.size()]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ private void validateStaticIPReport(GraphContext context)
util.loadPage(reportPath);
Assert.assertTrue(util
.checkHardcodedIPInReport(
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (67, 32)",
"Line: 67, Position: 32", "127.0.0.1"));
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (65, 32)",
"Line: 65, Position: 32", "127.0.0.1"));
Assert.assertTrue(util
.checkHardcodedIPInReport(
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (723, 14)",
"Line: 723, Position: 14", "127.0.0.1"));
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (721, 14)",
"Line: 721, Position: 14", "127.0.0.1"));
Assert.assertTrue(util
.checkHardcodedIPInReport(
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (727, 14)",
"Line: 727, Position: 14", "127.0.0.1"));
"org.apache.wicket.protocol.http.mock.MockHttpServletRequest (725, 14)",
"Line: 725, Position: 14", "127.0.0.1"));

}

Expand Down Expand Up @@ -160,7 +160,7 @@ private void validateOverviewReport(GraphContext context)
util.checkFilePathEffort("Windup1x-javaee-example.war", "META-INF/maven/javaee/javaee/pom.properties", 0);
util.checkFilePathEffort("Windup1x-javaee-example.war/WEB-INF/lib/joda-time-2.0.jar",
"org.joda.time.tz.DateTimeZoneBuilder", 32);
util.checkMainEffort(2213);
util.checkMainEffort(2309);
util.checkAppSectionEffort("Windup1x-javaee-example.war", 2);
util.checkAppSectionEffort("Windup1x-javaee-example.war/WEB-INF/lib/joda-time-2.0.jar", 64);
util.checkAppSectionEffort("Windup1x-javaee-example.war/WEB-INF/lib/slf4j-api-1.6.1.jar", 16);
Expand All @@ -178,7 +178,7 @@ private void validateReportIndex(GraphContext context)
TestReportIndexReportUtil util = new TestReportIndexReportUtil();
util.loadPage(appReportPath);

Assert.assertTrue(util.checkIncidentByCategoryRow("optional", 292, 2213));
Assert.assertTrue(util.checkIncidentByCategoryRow("optional", 304, 2309));
}

/**
Expand Down

0 comments on commit e6a3496

Please sign in to comment.