mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Java: add test for Apache Camel dead-code analysis
This exercises code that detects Camel entry-points and marks them as live.
This commit is contained in:
13
java/ql/test/query-tests/DeadCode/camel/DeadClass.expected
Normal file
13
java/ql/test/query-tests/DeadCode/camel/DeadClass.expected
Normal file
@@ -0,0 +1,13 @@
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.java:23:14:23:29 | ExpressionClause | The class ExpressionClause is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.class:0:0:0:0 | ExpressionClause<? extends FilterDefinition> | ExpressionClause<? extends FilterDefinition> |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.java:23:14:23:29 | ExpressionClause | The class ExpressionClause is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/FilterDefinition.java:19:14:19:29 | FilterDefinition | The class FilterDefinition is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/FilterDefinition.java:19:14:19:29 | FilterDefinition | FilterDefinition |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.java:22:14:22:29 | OutputDefinition | The class OutputDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.class:0:0:0:0 | OutputDefinition<RouteDefinition> | OutputDefinition<RouteDefinition> |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.java:22:14:22:29 | OutputDefinition | The class OutputDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.class:0:0:0:0 | OutputDefinition<RouteDefinition> | OutputDefinition<RouteDefinition> |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.class:0:0:0:0 | ProcessorDefinition<RouteDefinition> | ProcessorDefinition<RouteDefinition> |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.class:0:0:0:0 | ProcessorDefinition<Type> | ProcessorDefinition<Type> |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | The class RouteDefinition is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
|
||||
| com/semmle/camel/DeadTarget.java:4:14:4:23 | DeadTarget | The class DeadTarget is entirely unused. | com/semmle/camel/DeadTarget.java:4:14:4:23 | DeadTarget | DeadTarget |
|
||||
| com/semmle/camel/DeadTarget.java:9:23:9:25 | Foo | The class Foo is only used from dead code originating at $@. | com/semmle/camel/DeadTarget.java:5:14:5:19 | getFoo | getFoo |
|
||||
1
java/ql/test/query-tests/DeadCode/camel/DeadClass.qlref
Normal file
1
java/ql/test/query-tests/DeadCode/camel/DeadClass.qlref
Normal file
@@ -0,0 +1 @@
|
||||
DeadCode/DeadClass.ql
|
||||
@@ -0,0 +1,8 @@
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:41:12:41:16 | value | The method value is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:41:12:41:16 | value | value |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:49:12:49:14 | uri | The method uri is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:49:12:49:14 | uri | uri |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:54:12:54:19 | property | The method property is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:54:12:54:19 | property | property |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:63:12:63:20 | predicate | The method predicate is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:63:12:63:20 | predicate | predicate |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:34:28:34:31 | from | The method from is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | The method configure is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
|
||||
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/impl/DefaultCamelContext.java:24:15:24:23 | configure | The method configure is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/impl/DefaultCamelContext.java:24:15:24:23 | configure | configure |
|
||||
| com/semmle/camel/javadsl/CustomRouteBuilder.java:8:15:8:23 | configure | The method configure is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
|
||||
1
java/ql/test/query-tests/DeadCode/camel/DeadMethod.qlref
Normal file
1
java/ql/test/query-tests/DeadCode/camel/DeadMethod.qlref
Normal file
@@ -0,0 +1 @@
|
||||
DeadCode/DeadMethod.ql
|
||||
1
java/ql/test/query-tests/DeadCode/camel/README
Normal file
1
java/ql/test/query-tests/DeadCode/camel/README
Normal file
@@ -0,0 +1 @@
|
||||
Note that the CustomRouteBuilder method is regarded as "dead" because it would normally override a public library method and so be a `LibOverrideMethodEntry`, but because our library stubs are implemented as source code this isn't recognised. Similarly parts of our stubs appear dead. To confirm this is in fact ok, replace the stubs directory with a real Camel jar file.
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
import org.apache.camel.Consume;
|
||||
|
||||
/** Class is live because it is constructed as a bean. Method is live because it is annotated. */
|
||||
public class AnnotatedTarget {
|
||||
|
||||
@Consume(uri = "activemq:test")
|
||||
public Foo getFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code <bean ref="...">} tag in a Spring XML defined route.
|
||||
*/
|
||||
public class BeanRefTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code <bean beanType="...">} tag in a Spring XML defined route.
|
||||
*/
|
||||
public class BeanTypeTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
/** Dead because it is not referenced in the {@code config.xml} file, or in the Java DSL. */
|
||||
public class DeadTarget {
|
||||
public Foo getFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
/** A bean referred to in a method element in the config.xml file. */
|
||||
public class MethodBean {
|
||||
public Foo getFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code <to uri="..">} tag in a Spring XML defined route.
|
||||
*/
|
||||
public class ToTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.impl.DefaultCamelContext;
|
||||
|
||||
public class CustomRouteBuilder extends RouteBuilder {
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("direct:test")
|
||||
.to("bean:dslToTarget")
|
||||
.bean(DSLBeanTarget.class)
|
||||
.bean(new DSLBeanObjectTarget())
|
||||
.beanRef("dslBeanRefTarget")
|
||||
.filter()
|
||||
.method("dslMethodBean");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DefaultCamelContext camelContext = new DefaultCamelContext();
|
||||
camelContext.addRoutes(new CustomRouteBuilder());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code bean(new DSLBeanObjectTarget())} call in a RouteBuilder.
|
||||
*/
|
||||
public class DSLBeanObjectTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code beanRef("dslBeanRefTarget")} call in a RouteBuilder.
|
||||
*/
|
||||
public class DSLBeanRefTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code bean(DSLBeanTarget.class)} call in a RouteBuilder.
|
||||
*/
|
||||
public class DSLBeanTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
/** A bean referred to in the CustomRouteBuilder. */
|
||||
public class DSLMethodBean {
|
||||
public Foo getFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.semmle.camel.javadsl;
|
||||
|
||||
/**
|
||||
* All public methods in this class are considered to be live because this class is registered in a
|
||||
* {@code to("bean:dslToTarget")} call in a RouteBuilder.
|
||||
*/
|
||||
public class DSLToTarget {
|
||||
public Foo applyFoo(Foo foo1) {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static class Foo {}
|
||||
}
|
||||
34
java/ql/test/query-tests/DeadCode/camel/config.xml
Normal file
34
java/ql/test/query-tests/DeadCode/camel/config.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:camel="http://camel.apache.org/schema/spring"
|
||||
xmlns:cxf="http://camel.apache.org/schema/cxf"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
|
||||
">
|
||||
|
||||
<bean id="annotatedTarget" class="com.semmle.camel.AnnotatedTarget"/>
|
||||
|
||||
<bean id="dslBeanRefTarget" class="com.semmle.camel.javadsl.DSLBeanRefTarget"/>
|
||||
<bean id="dslToTarget" class="com.semmle.camel.javadsl.DSLToTarget"/>
|
||||
<bean id="dslMethodBean" class="com.semmle.camel.javadsl.DSLMethodBean"/>
|
||||
|
||||
<bean id="beanRefTarget" class="com.semmle.camel.BeanRefTarget"/>
|
||||
<bean id="toTarget" class="com.semmle.camel.ToTarget"/>
|
||||
<bean id="methodBean" class="com.semmle.camel.MethodBean"/>
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<route id="wsRoute">
|
||||
<from uri="cxf:bean:camelTargetEndpoint"/>
|
||||
<bean ref="beanRefTarget"/>
|
||||
<bean beanType="com.semmle.camel.BeanTypeTarget"/>
|
||||
<to uri="bean:toTarget?foo"/>
|
||||
<filter>
|
||||
<method ref="methodBean" />
|
||||
</filter>
|
||||
</route>
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
2
java/ql/test/query-tests/DeadCode/camel/options
Normal file
2
java/ql/test/query-tests/DeadCode/camel/options
Normal file
@@ -0,0 +1,2 @@
|
||||
//semmle-extractor-options: --javac-args -cp
|
||||
//semmle-extractor-options: ${testdir}/../../../stubs/apache-camel-4.0.6/:${testdir}/../../../stubs/jaxb-api-2.3.1/
|
||||
Reference in New Issue
Block a user