오늘도 행복하다.
HOME
TAG
MEDIA
LOCATION
GUEST
ADMIN
WRITE
Category
분류 전체보기
(1012)
행복이야기
(24)
日常茶飯事
(601)
雜동사니
(285)
로그
(1)
ㅈㅇ.삭제.메모
(0)
산행->이동
(0)
野生野死
(38)
꺼리
(0)
업무
(1)
미완
(0)
운전, 車
(0)
상단, 공지, 계속
(0)
캠핑, 야영, 바깥놀이
(1)
eToy
(0)
Recent Article
Recent comment
My Link
지원이랑
Notice
Tag Cloud
Tomcat
Subversion
갈거야
山行
먹거리
QPA2018 프로젝트
YBD 프로젝트
여의도
wsp나중에
WSP 프로젝트
Enterprise Portal
자료
테스트@
영어
Eclipse
아키공부@
쇼핑
아웃도어 장비
[비교]
sap
1
grails
NTC 프로젝트
PHT 프로젝트
정리필요
IKP 프로젝트
YNP 프로젝트
노숙일지
9
야구
Calender
«
2025/02
»
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Archive
'멤버변수 공유@'에 해당되는 글
1
건
2009.03.23
멤버변수 문제점
멤버변수 문제점
日常茶飯事
2009. 3. 23. 19:26
Posted by
pantarei
멤버변수 문제점
public class NoticeCommand implements Command { private String next; public NoticeCommand (String next){ this.next = next; } public String execute( String msg ) { ... try { ... if("UnavailableException".equals(msg)){ ... throw new UnavailableException(); }else if("".equals(msg)){ ... }else{ } } catch (UnavailableException e) { logging ... next = "/"; } catch (Exception e) { next = "/error.jsp"; } return next; } }
public class Main{ private static final Map<String, Command> commands = new HashMap<String, Command>(); static{ commands.put("list", new NoticeCommand("/list.jsp")); ... } private static Command lookupCommand(String cmd){ ... return command; } public static void main(String[] args) { Command command = lookupCommand("list"); String result = command.execute("UnavailableException"); System.out.println(result); result = command.execute(""); System.out.println(result); } }
대충 이런 코드인데,
UnavailableException 이 발생한 뒤부터 예외가 발생하지 않아도 result 는 / 이다.
로거를 찍어봐도 예외는 발생하지 않는데 result 는 / 다.
문제는 next 변수를 잘못 사용했기 때문에 발생했다.
NoticeCommand 는 한번 생성한 뒤 계속 재사용되므로 next 변수를 변경하지 말던가 로컬변수로 돌린다.
웹 환경의 다중 스레드에 의해서 접근되는 경우 더욱 조심해야 한다.
공유하기
게시글 관리
오늘도 행복하다.
저작자표시
비영리
변경금지
▲
1
▼
티스토리툴바
Recent comment