Migrate Java code to separate QL repo.

This commit is contained in:
Pavel Avgustinov
2018-08-30 10:48:05 +01:00
parent d957c151a6
commit 846c9d5860
2319 changed files with 134386 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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()

View File

@@ -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>