001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.weaver.privilizer.example; 020 021import org.apache.commons.weaver.privilizer.Privileged; 022 023public class NoArgs { 024 025 @Privileged 026 void throwAwayFoo() { 027 System.getProperty("foo"); 028 } 029 030 @Privileged 031 String getFoo() { 032 return System.getProperty("foo"); 033 } 034 035 @Privileged 036 Boolean getTrue() { 037 System.getProperty("foo"); 038 return Boolean.TRUE; 039 } 040 041 @Privileged 042 boolean getFalse() { 043 System.getProperty("foo"); 044 return false; 045 } 046 047 public static class CheckedException1 extends Exception { 048 private static final long serialVersionUID = 1L; 049 } 050 051 public static class CheckedException2 extends Exception { 052 private static final long serialVersionUID = 1L; 053 } 054 055 @Privileged 056 void throwingCheckedException1() throws CheckedException1 { 057 System.getProperty("foo"); 058 throw new CheckedException1(); 059 } 060 061 @Privileged 062 Integer throwingCheckedException2() throws CheckedException1, CheckedException2 { 063 System.getProperty("foo"); 064 throw new CheckedException2(); 065 } 066}