mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Migrate Java code to separate QL repo.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// bean class
|
||||
public class ContentService {
|
||||
private TransactionHelper helper;
|
||||
|
||||
// This method does not match the property in the bean file.
|
||||
public void setHelper(TransactionHelper helper) {
|
||||
this.helper = helper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
The absence of a matching setter method for a property that is defined in a Spring XML bean causes a validation error when the project is compiled.
|
||||
</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
<p>
|
||||
Ensure that there is a setter method in the bean file that matches the property name.
|
||||
</p>
|
||||
|
||||
</recommendation>
|
||||
<example>
|
||||
|
||||
<p>The following example shows a bean file in which there is no match for the setter method that is
|
||||
in the class.</p>
|
||||
|
||||
<sample src="MissingSetters.xml" />
|
||||
|
||||
<p>This is the bean class.</p>
|
||||
|
||||
<sample src="MissingSetters.java" />
|
||||
|
||||
<p>The property <code>transactionHelper</code> should instead have the name <code>helper</code>.</p>
|
||||
|
||||
</example>
|
||||
<references>
|
||||
|
||||
|
||||
<li>
|
||||
Spring Framework Reference Documentation 3.0:
|
||||
<a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-setter-injection">3.4.1.2 Setter-based dependency injection</a>.
|
||||
</li>
|
||||
|
||||
|
||||
</references>
|
||||
</qhelp>
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @name Missing setters for property dependency injection
|
||||
* @description Not declaring a setter for a property that is defined in a Spring XML file causes a
|
||||
* compilation error.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @precision low
|
||||
* @id java/spring/missing-setter
|
||||
* @tags reliability
|
||||
* maintainability
|
||||
* frameworks/spring
|
||||
*/
|
||||
import java
|
||||
import semmle.code.java.frameworks.spring.Spring
|
||||
|
||||
from SpringProperty p
|
||||
where
|
||||
not p.getEnclosingBean().isAbstract() and
|
||||
not exists(p.getSetterMethod())
|
||||
select p, "This property is missing a setter method on $@.",
|
||||
p.getEnclosingBean().getClass() as c, c.getName()
|
||||
@@ -0,0 +1,7 @@
|
||||
<bean id="contentService" class="documentation.examples.spring.ContentService">
|
||||
<!--BAD: The setter method in the class is 'setHelper', so this property
|
||||
does not match the setter method.-->
|
||||
<property name="transactionHelper">
|
||||
<ref bean="transactionHelper"/>
|
||||
</property>
|
||||
</bean>
|
||||
Reference in New Issue
Block a user